I have a text file that looks something like this:
foo
bar
zip
rar
tar
I need to use a bash script on OSX to make a new text file after every new line like this:
cat text1.txt
foo
cat text2.txt
bar
cat text3.txt
zip
cat text4.txt
rar
cat text5.txt
tar
Best Answer
You can use
csplit
. It does the job well, except that it's somewhat inflexible regarding the output file names (you can only specify a prefix, not a suffix) and you need a first pass to calculate the number of pieces.The GNU version, but not the OSX version, has extensions that solve both issues.
Alternatively, if
csplit
is too inflexible, you can use awk.