OT: Need some shell scripting hints ;)
Michael Baer
yellowdog-general@lists.terrasoftsolutions.com
Tue Oct 7 15:25:01 2003
>>>>> "Alexander" == Alexander Holst <holst@fh-pforzheim.de> writes:
Alexander> Hi, I'm stuck with writing a shell script that is
Alexander> supposed to read a text file line by line.
Alexander> My goal is to have some sort of a loop that is passed
Alexander> through once for every line in my text file and ends
Alexander> after the iteration for the last line.
Alexander> Something like:
Alexander> while [ readTheFile TextFile.txt LineByLine into LINE ]
Alexander> do
Alexander> some stuff with $LINE # for every line one iteration
Alexander> done
Alexander> Anything like:
Alexander> for LINE in (every line of TextFile.txt) do
Alexander> some stuff with $LINE # for every line one iteration
Alexander> done
Alexander> would do the trick too.
Alexander> Either it is too late allready, or I can't get the
Alexander> syntax right. Any help/ideas appreciated,
Since no one suggested it (and admittedly it doesn't quite fit your
shell requirement), but depending on what you're actually after, you
might consider perl.
e.g. change all lines in thefile.txt with 'Red Hat' in them to
'Yellow Dog'.
/usr/bin/perl -p -i -e 's/Red Hat/Yellow Dog/g' thefile.txt
- Mike
--
ydl@mikesoffice.com