[svlug] looping through a file line by line

Tim tim at tetro.net
Mon Apr 21 16:53:14 PDT 2003


On Mon, Apr 21, 2003 at 04:44:24PM -0700, John McDonnell wrote:
> I have a file that I want to split up line by line and I can't seem to
> do this properly. Googling isn't exactly helpful - it turns up many
> results, all with the search terms, but the S/N is pretty low.
> 
> Anyway, how should I go abuot doing this? Using 'for' and eitehr cut
> or cat gives me each word.

I guess it depends on what you want to do with each line, but check out
awk or xargs -i.  There is lot you can do with awk, but if its just
something simple, xargs -i might work.  This runs echo once for each
line in inputfile, passing it the line as its first argument:

   xargs -i echo {} < inputfile

   - Tim



More information about the svlug mailing list