Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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