Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bash script with AWK <input.file (holding multiple values)

Status
Not open for further replies.

blnix

MIS
Jun 7, 2006
4
US
trying to write a script for installing applications based on input from a file. the file is in format 'column1',<tab>'column2'.

Values from each column get used as imput at different places in the command. here's what i've started with.

CODE snippet
for port in `cat $1|awk '{print $1, $2}'`|read var1 var2
do
printf "\n \n Creating components for $var1 \n"
COMMAND $var1
when_error "check $LOG for errors"
COMMAND PATH/$var2.ear $var2 $var1
when_error "check $LOG for errors"

done

I've tried this several different ways. each line needs to be read one at a time till EOF....what's the best approach i should be take?
 
Something like this ?
IFS=",$IFS" while read var1 var2
do
printf "\n \n Creating components for $var1 \n"
COMMAND $var1
when_error "check $LOG for errors"
COMMAND PATH/$var2.ear $var2 $var1
when_error "check $LOG for errors"
done < $1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you for the help! but I do get an error when i implement it which i'm not familar with.

"$1: ambiguous redirect
 
In fact:
done < /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
true, sorry. wasn't thinking that way. That is what I was trying to avoid . Not to have to edit the script for every file, just the file since there are many. Perhaps that's just the way I've got to it. Or I was thinking of splitting the file into two tmp files.
Wait...duh...i'll just ask them for the filename.

done < $FILEPATH/$U_INPUT

Thank you for your help.
 
Excellent!!! I threw it all together and it works beautifully.

Life Saver!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top