I have Linux CLI and 1 txt file with a couple of hundred entries like this:

alalalala asasasaas addfsfdfd

I want to make files with text inside as:

alalalala

etc..

please advice.

link|improve this question
1  
You can do this using command-line tools. So, unless you want a programming solution to this, this belongs on superuser.com. – Jason Jan 18 '10 at 17:10
You haven't actually told us what you want to accomplish. DO you want to put each white-space separated word in it's own file? How should the resultant files be named? What should be done with duplicates? Please specify. – dmckee Jan 19 '10 at 1:56
feedback

migrated from stackoverflow.com Jan 20 '10 at 17:05

This question came from our site for professional and enthusiast programmers.

2 Answers

awk '{ for(i=1;i<=NF;i++) { print $i > $i".txt"}   }' file
link|improve this answer
feedback

What names should have the generated files?

How I would do it in Python:

contents = open("file.txt").read()
entries = contents.split()  # split by whitespace
for entry in entries:
  f = open(entry + ".txt", "w")
  f.write(entry + "\n")
  f.close()

But I must admit that the one-liner from ghostdog74 looks very nice :)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown