6

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?

5
  • 1
    what does file mytextfile.txt return? Commented Apr 9, 2014 at 18:38
  • It returns the same file, but renamed as xaa.txt Commented Apr 9, 2014 at 18:40
  • I thought i was supposed to get 30 new text files where each file contains one line of text? Commented Apr 9, 2014 at 18:41
  • @jenn file is a utility that shows file type. When you run file mytextfile.txt, file will print a line like "mytextfile.txt: ASCII text, with CR line terminators". 1_CR is asking what it shows for your file. Commented Apr 9, 2014 at 18:42
  • Well, obviously that's irrelevant now that you posted your actual command. Amusingly, the first command you posted, split -l 2 mytextfile.txt, would almost have worked. Commented Apr 9, 2014 at 18:43

2 Answers 2

8

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

Sign up to request clarification or add additional context in comments.

4 Comments

It worked for me. I created a 30 line file, did split -l 1, and it created files xaa through xbd.
I realized that the problem was me copying from a csv file to a text file.
and this is required:%s/^V^M/^V^M/g
I am getting a new line at the end of each file , what should be done to remove it ?
2

Try awk

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.