Operating System - HP-UX
1753365 Members
6022 Online
108792 Solutions
New Discussion юеВ

awk help and shell script

 
kholikt
Super Advisor

awk help and shell script

I have a shell script to extract some omniback report

I wish to remove some of the column.

QAS Completed trans 12/11/03 05:00:06 1071090006 12/11/03 05:04:07 1071090247 0:00 0:04 0.37 1 0 3 0 0 0 4 4 4 100% root.sys@cm.esc 2003/12/11-14

In my shell script
cat $DESTDIR/ses.final | while read LINE
do
LINE2=`echo $LINE | awk '{print $1 $2 $3}'`
done

Is it possible to put \t (tab) in between $1 $2 & $3
abc
5 REPLIES 5
Jean-Louis Phelix
Honored Contributor

Re: awk help and shell script

Hi,

You just need to use printf instead of print :

LINE2=`echo $LINE | awk '{printf "%s\t%s\t%s\n", $1, $2, $3}'`

Regards.
It works for me (┬й Bill McNAMARA ...)
Sanjay_6
Honored Contributor

Re: awk help and shell script

Hi,

Try

LINE2=`echo $LINE | awk '{print $1,"\011",$2,"\011",$3}'`

Hope this helps.

Regds
Sanjay_6
Honored Contributor

Re: awk help and shell script

Hi,

you can use the \t suggested by Jean with the print command also.

LINE2=`echo $LINE | awk '{print $1,"\t",$2,"\t",$3}'`

hope this helps.

Regds
Graham Cameron_1
Honored Contributor

Re: awk help and shell script

No need to use cat while read, you can do the whole thing with awk...

awk '
{printf ("%s\t%s\t%s\n", $1, $2, $3)}
' $DESTDIR/ses.final


-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
curt larson_1
Honored Contributor

Re: awk help and shell script

or just do it all in the shell

cat $DESTDIR/ses.final |
while read var1 var2 var3
do
print "$var1\t$var2\t$var3"
done