awk print correct lines when certain columns are blank
hi, i got a text file and i would like to print all the lines where $5 == "CP". the problem is awk thinks that for certain lines the column i'm interested in is $3:
Code:
schneidz@lq:temp> cat test.lst thanks, |
Code:
awk '{if (NF==10 && $5=="CP") print $0; else if (NR!=10 && $2=="CP" || $3=="CP" || $4=="CP") print $0}' test.lst |
|
If the string CP never appears in other fields, you can simply use a regular expression:
Code:
gawk '/CP/' test.lst Quote:
Code:
gawk 'index($0,"CP") == 26' test.lst |
hi all
first of all i'd like to apologise for my really bad english :( well, i have a similar problem with awk Recently i decided to replace all my Solaris systems at work, with linux (fedora).. actually, that was not my decision, but anyway :P The problem is the way that awk command prints one of my values. See bellow to understand. Code:
#!/bin/csh The output of this (final.log) in Solaris is ATH ,MIL ,20080401152000 ,1 ,32 ,2 ,0 which is the output i need. But, the output in Linux is ATH ,MIL ,2.00804e+13 ,1 ,32 ,2 ,0 and i have problem with the bold format. Any ideas? Many Thanks Panos |
I tried something similar and it printed out without the scientific notation.
Code:
echo $NOW | awk '{ print "ATH", "," "MIL" "," '$NOW'}' |
Quote:
|
solved... i put double quotes on '$NOW' ... "'NOW'" is the solutions...
|
Quote:
Code:
echo $NOW | gawk '{ printf "ATH ,MIL ,%d\n",'$NOW' }' |
Quote:
|
Quote:
Code:
if(substr($0, <char pos>, 2) == "CP") { print $0; } |
thanks for all your suggestins:
colucix and JWPurple post were most useful |
All times are GMT -5. The time now is 03:23 AM. |