1754930 Members
2693 Online
108827 Solutions
New Discussion юеВ

awk help

 
SOLVED
Go to solution
Tapas Jha
Valued Contributor

awk help

Hi,
Can anyone help me to modify my script? I just want to get rid of single quote from Name columns. How can i use sed,tr from within printf statement? Or else there may be other way.
Below is my script.

#!/bin/sh
DIR="/home/tapas/"
DT=`date +%d`
DT=`expr $DT - 1`
DTCT=`echo $DT|wc -m`
FL="logfile.20040429"
ll $DIR/$FL > /dev/null
RFL="report`date +%Y%m$DT`.xls"
echo "TIME\t\tNAME\t\tFROM\t\tVIA">$RFL
grep -e "- OK --" $FL|awk '
{
if ( $9 == "via" )
{
printf $4"\t"$8"\t"$12"\t"$10"\n"
}
else
{
printf $4"\t"$8"\t"$10"\n"
}
}
'>>$RFL

Below is the logfile.
Thu Apr 29 07:43:16 2004: created by PID 5173 Version 5.1.1A AAA_POLL BINARY_AATV CHK_COUNTS CHK_SHELLS CHK_TOKEN EMAIL LAS = 1.7.1 (NO-HGAS) Y2K up since Sun Apr 25 07:59:11 2004
Thu Apr 29 07:43:16 2004: fsmid check+las-logall-1.0; hostname bombay; dns-name bombay.abc.com
Thu Apr 29 07:43:16 2004: Switched from '/var/opt/aaa/logs/logfile.20040428' to
'/var/opt/aaa/logs/logfile.20040429'
Thu Apr 29 07:43:16 2004: Received-Authentication: 2/294 'tapas' via a.b.c.d
from d.e.f.g port 133 PPP
Thu Apr 29 07:43:16 2004: find_auth_ent: no default authfile data structure
Thu Apr 29 07:43:16 2004: Authentication: 2/294 'tapas' via a.b.c.d from
d.e.f.g port 133 PPP - OK -- total 0, holding 0
Thu Apr 29 07:43:16 2004: created by PID 5173 Version 5.1.1A AAA_POLL BINARY_AATV CHK_COUNTS CHK_SHELLS CHK_TOKEN EMAIL LAS = 1.7.1 (NO-HGAS) Y2K up since Sun Apr 25 07:59:11 2004
Thu Apr 29 07:43:16 2004: fsmid check+las-logall-1.0; hostname bombay; dns-name bombay.abc.com

Output is like below. But instead of 'tapas' i want tapas( Not any quatation)
TIME NAME FROM VIA
07:43:16 'tapas' d.e.f.g a.b.c.d
Tapas Jha
5 REPLIES 5
Leif Halvarsson_2
Honored Contributor

Re: awk help

rty to pipe via tr:

|tr -d \'
Roberto Polli
Trusted Contributor

Re: awk help

you can add one line like

regsub("'","",$8)

in your awk script.

regsub makes a substitution in your script.
check manual 'cause awk changes between various unix flavours.

Peace, R.
Tapas Jha
Valued Contributor

Re: awk help

Hi,
Can u tell me where exactly insert tr or regsub/gsub in my script? I understand this is a simple thing but i am not able to solve right now.

Rgds
Tapas
Tapas Jha
Francisco J. Soler
Honored Contributor
Solution

Re: awk help

Hi,
you can put a substr command in the printf statement:

printf $4"\t"substr($8,2,length($8)-2)"\t"$12"\t"$10"\n"

this prints the 8th field without the first and last characters.

Frank.
Linux?. Yes, of course.
Tapas Jha
Valued Contributor

Re: awk help

Thanx Solar.
I was not able to solve this simple problem. Actually in one of my earlier script
i had solution similar to yours. Thanx a lot.

Rgds
Tapas
Tapas Jha