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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using IFS and printf

Status
Not open for further replies.

jalge2

Technical User
Feb 5, 2003
105
US
Hi all. My trouble I think is with IFS. The log that I am trying to output is separated only by commas. IFS uses spaces so in my script, I used $IFS="," but the script doesn't seem to like that. Can anyone help. Here's what I have so far. # /bin/ksh!
$IFS= ","
echo "\tPlease enter the battery number you wish to search for..."
read ans

if [[ $ans != 0 ]]

then
cat /dso/eis/log/batlog.log.* | grep $ans > /dso/eis/log/battsearch.log
awk 'BEGIN { print "LRT DATE TIME OLD BATT NAME DEPT IN/OUT NEW BATT STATUS"
print "--- ---- ---- -------- ---- ---- ------ -------- ------"}
{ printf "%-5s%-5s%-5s%-5s %s\n", $1, $2, $3, $4, $6, $7, $8, $9 }' /dso/eis/log/battsearch.log
else
exit


fi

echo "\tWould you like to print this? (y/n)"
read ans1

if [ $ans1 = "y" -o $ans1 = "Y" ]

then
lp -dps@pr7 /dso/eis/log/battsearch.log

else
exit
fi
$IFS=" "


Thanks for the help.

 
Defining a variable is without the "$" ie. IFS="," not $IFS=",". If you want to use it's content, you need the $ like
echo $IFS
,

As you are yousing awk already and you need an Input Field Separator, better use the awk variable FS, which stands for Field Separator and is used like:

cat passwd| awk 'BEGIN{FS=":"} ...... and so on

If you wanna have an Output Field Separator, define it with OFS inside awk.
Maybe this thread is better placed in "AWK" and/or "Unix Scripting".

laters
zaxxon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top