Reputation: 115
I am writing my first script so forgive me for my beginners mistakes. I've been looking all over stack overflow and have not found anything that helps me with this problem.
The script will use WinSCP to access folders in a Raspberry Pi and split a file that has become too large. Then it will copy the sub files over to a Desktop using WinSCP again. We know how to split the file and how to move things over to WinSCP, but since we cannot control the sub file names, we thought it would make more sense to store them in a folder and move that over.
This is what I have thus far:
#!/bin/bash
# Data Collector Script
mkdir $output
mv split -l 20000 helloworld.txt output //This is the line where I get stuck
Is there a way I can directly split the files into an output file? I would move them manually but the file names are random.
Upvotes: 3
Views: 2286
Reputation: 6348
@Rob has the answer, and here's a small script using it that tries to defend against BASH's deficiencies as a programming language:
#!/bin/bash
# make BASH fail on errors and unset variables
set -eu
output='output_dir'
file_to_split="helloworld.txt"
# make the directory
# -p means no errors if the directory is there already
mkdir -p "${output}"
split -l 20000 "${file_to_split}" "${output}/${file_to_split}."
Upvotes: 2
Reputation: 168626
Try this:
split -l 20000 helloworld.txt output/x
Reference: http://linux.die.net/man/1/split
Upvotes: 6