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

piping in awk

Status
Not open for further replies.

segment

ISP
Jun 15, 2004
225
US
no piping allowed

Alright, so a quick question about piping in awk...

awk 'a !~ $0; {a=$0}' (equivalent to uniq)
awk '! a[$0]++' (equivalent to uniq)
awk '/something/' (equivalent to grep something)
awk '!/something/' (equivalent to grep -v something)

So now I have a cdr file... Its normal output...

"","1001","1","fxobox","""1001"" <1001>","SIP/1001-f912","SIP/1003-c091","Dial","SIP/1003","2006-11-02 15:22:00","2006-11-02 15:22:01","2006-11-02 15:22:04",4,3,"ANSWERED","DOCUMENTATION"


[root@mybox cdr-csv]# awk -F "," '/fxobox/{print $2,$4,$10,$11}' filename
"1001" "fxobox" "2006-11-02 15:22:00" "2006-11-02 15:22:01"
"1001" "fxobox" "2006-11-02 15:22:00" "2006-11-02 15:22:01"
"1001" "fxobox" "2006-11-02 16:34:47" "2006-11-02 16:34:48"

[root@mybox cdr-csv]# awk -F "," '/fxobox/{print $2,$4,$10,$11;! a[$0]++;/16:34/}' filename
"1001" "fxobox" "2006-11-02 15:22:00" "2006-11-02 15:22:01"
"1001" "fxobox" "2006-11-02 15:22:00" "2006-11-02 15:22:01"
"1001" "fxobox" "2006-11-02 16:34:47" "2006-11-02 16:34:48"

What gives? In theory isn't this awk -F "," '/fxobox/{print $2,$4,$10,$11;! a[$0]++;/16:34/}' nothing more than the equivalent of:

awk -F "," '/fxobox/{print $2,$4,$10,$11}' filename|uniq|grep -v "16:34"

[root@mybox cdr-csv]# awk -F "," '/fxobox/{print $2,$4,$10,$11}' filename|uniq|grep -v "16:34"
"1001" "fxobox" "2006-11-02 15:22:00" "2006-11-02 15:22:01"


Just curious nothing major. Just wanted to understand pipes in awk a little better. Thanks way in advance

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
Hi

No, those two lines are not equivalent. I your composed code first [tt]print[/tt], so all line will appear on standard output, regardless what happens next. And while the output is not redirected, that will be the final result.

Try this way :
Code:
awk -F',' '/fxobox/ && !/16:34/ && !a[$2,$4,$10,$11]++{print $2,$4,$10,$11}'

Feherke.
 
Furthermore, don't confuse pattern and action.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top