Another one I always use - doing some command over every line of a file:
for i in `cat foo.txt`; do echo $i; done
Nice and simple, but works a treat.
Found this useful? Then Digg It.
« Inline editing with sed | Main | My new obsession »
Another one I always use - doing some command over every line of a file:
for i in `cat foo.txt`; do echo $i; done
Nice and simple, but works a treat.
Found this useful? Then Digg It.
This page contains a single entry from the blog posted on September 24, 2006 9:37 PM.
The previous post in this blog was Inline editing with sed.
The next post in this blog is My new obsession.
Many more can be found on the main index page or by looking through the archives.
Comments (2)
This doesn't work using unxutils (for win32: see http://unxutils.sf.net ) if the file names have spaces in.
Posted by anon | November 13, 2007 4:42 PM
Posted on November 13, 2007 16:42
Yeah, that won't do what you expect if there are lines with whitespace in them.
If you strictly want to process things a line at a time, you can do something like--
cat foo.txt | while read i; do echo $i; done
Posted by jesse | July 19, 2008 10:59 PM
Posted on July 19, 2008 22:59