jxn
jxn

Reputation: 8055

split each line in a text file into new text files via command line

I have a text file with 30 lines. I would like to split it up by line where each line will be in a new text file.

I used this command in the command line but didnt get any useful output except the exact same 30 line file but just renamed as "xaa" :

split -l 1 mytextfile.txt

Am i doing something wrong here?

Upvotes: 6

Views: 8096

Answers (2)

drkunibar
drkunibar

Reputation: 1337

Try awk

cat  mytextfile.txt  |  awk '{ print $0 > "my_splittet_textfile_"NR".txt"}'

Upvotes: 2

Mike Holt
Mike Holt

Reputation: 4612

You're using the -l argument incorrectly. The value you pass in with -l is the number of lines to put into each piece. So you're taking a 30 line file and splitting into ... a single 30 line file.

You need to do split -l 1 mytextfile.txt

Upvotes: 8

Related Questions