Creating new files each containing one line per file from a given text file

Shantanu.ade

Right off the assembly line
Joined
Oct 2, 2012
Messages
1
Hello everyone !
I am referring shell scripting. So I came across various strengths of scripting. I was just thinking whether following idea is possible:
suppose I am having a text file containing 10 lines. Now I want to create file1 with line1 of it. Then file2 having line2 of text file and so on. So for this 10 lines in the text file I'll be having 10 new files containing a single line.

Also while giving solution, if you explained it a little, it'll be more helpful since I am new to scripting.
 

mediator

Technomancer
Joined
Mar 18, 2005
Messages
2,484
It is a very basic form of shell scripting. You can find all the explanation here : bash shell script read file line by line.

Regarding copying individual lines to files, you can simply echo the line to the file e.g "echo $line > file$i" where $line will be the value of the corresponding line and file$i the successive count of the file e.g file1, file2, file3 etc.
 
Top