Hi all. I'll try to lay out the scenario. We have certain battery numbers that append to a log file. They look like this:
LRT231,07/01/03,00:01,9901789,Patricia Welty,Receiving,IN,4130801,PROD
LRT231,07/01/03,00:01,9901789,Patricia Welty,Receiving,OUT,0160503,PROD
I am creating a script that will grep for any battery number that I enter, in this case, 4130801 is the battery number. I'm using printf to display the information but it's not working because of the comma's in between the certain fields in the log file. I'm trying to figure out how to use IFS and OFS but am having some trouble. My script looks like this:
# /bin/ksh!
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
The output that I get is...
LRT DATE TIME OLD BATT NAME DEPT IN/OUT NEW BATT STATUS
--- ---- ---- -------- ---- ---- ------ -------- ------
,06/29/03,22:04,9901538,CoryCole,DCO,OUT,4270801,PROD
LRT194,07/01/03,08:45,9901858,ShelleyNoe,Receiving,OUT,4270801,PROD
All one line of course. I'm trying to figure out the field separators but am having trouble. Can someone help me figure out where they need to be in order to get this to output correctly.
Thanks
jalge2
LRT231,07/01/03,00:01,9901789,Patricia Welty,Receiving,IN,4130801,PROD
LRT231,07/01/03,00:01,9901789,Patricia Welty,Receiving,OUT,0160503,PROD
I am creating a script that will grep for any battery number that I enter, in this case, 4130801 is the battery number. I'm using printf to display the information but it's not working because of the comma's in between the certain fields in the log file. I'm trying to figure out how to use IFS and OFS but am having some trouble. My script looks like this:
# /bin/ksh!
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
The output that I get is...
LRT DATE TIME OLD BATT NAME DEPT IN/OUT NEW BATT STATUS
--- ---- ---- -------- ---- ---- ------ -------- ------
,06/29/03,22:04,9901538,CoryCole,DCO,OUT,4270801,PROD
LRT194,07/01/03,08:45,9901858,ShelleyNoe,Receiving,OUT,4270801,PROD
All one line of course. I'm trying to figure out the field separators but am having trouble. Can someone help me figure out where they need to be in order to get this to output correctly.
Thanks
jalge2