Re: OT: shell scripting problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Alexander Dalloz wrote:
Am Mi, den 18.05.2005 schrieb linux.whiz@xxxxxxxxx um 0:55:


My brain is fried.  I know there is a simple answer to this but I'm
drawing a blank.  I want to run a script against the contents of a
text file.  The text file is just my users' first name, middle initial
and last name like this:

John A Smith
Mary P James
Sally R Jones
Fred Q Davis

What I want to do is for each user in this file, run a script.  I
tried to do this:

for i in `cat textfile`; do
 myscript.sh $i
done

Remember that, by default, bash thinks spaces separate fields. You could add a couple of lines such as:

	OLDIFS=$IFS
	IFS=$'\n'

to the beginning of your script to change the field separator to just
newline (by default, it's "<space><tab><newline>").  Don't forget to
clean that up via:

	IFS=$OLDIFS

at the end of the script (not really necessary, but one should clean up
after oneself).
----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens@xxxxxxxxxxxxxxx -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-     Is that a buffer overflow or are you just happy to see me?     -
----------------------------------------------------------------------


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux