problem:
Using Linux or OS X, I would like to replace spaces with newline characters in a file and output the result to a new file.For instance, if my file's contents look like the following:
Monday Tuesday Wednesday Thursday Friday
The output should look like:
Monday
Tuesday
Wednesday
Thursday
Friday
Tuesday
Wednesday
Thursday
Friday
solution:
In the terminal, a simple solution would be to use the 'tr' command, for instance:
cat infile.txt | xargs | tr -s ' ' '\n' > outfile.txt
No comments:
Post a Comment