help with Awk or nawk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help with Awk or nawk
# 1  
Old 11-28-2005
help with Awk or nawk

Can anyone explain to me why the first line doesn't work and the second seems to work fine. I am trying to find all occurances of text within a certain column (col 13) that start with the character V, I suppose it sounds simple but I have tried using the following but don't really understand what the periods are actually doing.

So the first line doesn't work yet the second does seem to...whats the difference...in laymans terms please

awk '{if ($13 ~ ".*V.") print}' text.file > newtext.file

awk '{if ($13 ~ ".*V.*..") print}' text.file

head text.file

SG99891970 G405H 25/10/05 29/10/05 C8 11 10 27/12/74 2712742214 31620 AB42 3JD VW01A
SG99926485 G405H 10/11/05 12/11/05 A1 36 10 01/11/80 0111802040 31620 AB42 5WA VW10
SG03130444 G405H 17/07/05 24/07/05 A1 36 10 18/09/27 blank 99995 CA11 7UF VW17
SG03130444 G405H 24/07/05 11/08/05 A1 18 43 18/09/27 blank 99995 CA11 7UF VW17
SG03144116 G405H 12/11/05 14/11/05 A1 36 10 10/05/84 blank 99961 DD3 0NH SW06
SG03128794 G405H 05/10/05 07/10/05 C8 11 10 22/07/53 blank 18343 DG1 1TQ VWD

Last edited by Gerry405; 11-28-2005 at 01:11 PM..
# 2  
Old 11-28-2005
well.... they BOTH work just fine under Sun's 'nawk'.

Quote:
Originally Posted by Gerry405
I am trying to find all occurances of text within a certain column (col 13) that start with the character V
Based on the definition above:
Code:
nawk '$13 ~ /^V.*/' text.file

# 3  
Old 11-28-2005
since you're really only looking for the first letter in the column, you could also try ...
Code:
awk '$13 ~ /^V/' text.file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk/Nawk Questions

Hi Guys, This is the Input: <xn:MeContext id="XXX012"> <xn:ManagedElement id="1"> <xn:attributes> <xn:userLabel>XXX012</xn:userLabel> <xn:swVersion>R58E68</xn:swVersion> </xn:attributes> </xn:ManagedElement> </xn:MeContext>... (4 Replies)
Discussion started by: smarones
4 Replies

2. Shell Programming and Scripting

Awk,nawk Help please

Hi Guys, I am in need of some help; I have an xml message file which contains personal details as shown below: , message=, message=, message=, message=, message=, message= I want to use nawk to parse these xml messages but I am new to awk and nawk. What I want is to get output... (7 Replies)
Discussion started by: James_Owen
7 Replies

3. Shell Programming and Scripting

awk or nawk in ksh

I am trying to use either awk or nawk in ksh88 to grep the word "Reason" in multiple files and than print the lines that say "Reason" in a particular format that is different from how they would normally print. The original input is as follows: ... (10 Replies)
Discussion started by: ther2000
10 Replies

4. UNIX for Dummies Questions & Answers

Help me to know about awk and nawk

Hi everyone, i am new to unix , so i want to know what is the use of awk and nawk. because in most of the place this cmds were used. so, if anyone provied the basic idea of this cmds, it will be much helpfull for me . . .. Thnks in Advance :) (9 Replies)
Discussion started by: natraj005
9 Replies

5. Shell Programming and Scripting

awk and nawk on Solaris

Why do they do two different things? Like on one version of UNIX you can use awk, but tehn if you move to Solaris then awk becomes something crap and you need to use nawk instead! whY!?!?!?! (4 Replies)
Discussion started by: linuxkid
4 Replies

6. Shell Programming and Scripting

comparing awk and nawk

Hi Guys, i tried these two commands. First in awk and nawk. The nawk command is running fine but the awk command is throwing error. What is wrong with the awk command. There are lot of awk commands running fine in my system d003:/usr/local/dsadm/dsprod>nawk 'NR = 1 {print " "$0}' a.txt ... (6 Replies)
Discussion started by: mac4rfree
6 Replies

7. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

8. UNIX for Dummies Questions & Answers

How to use awk instead of nawk?

Hi all, I can run the following script using nawk..However, I find that teh server dun support nawk.. May I know how to change teh script to use awk such that it will work? Very urgent.. thx! nawk 'BEGIN {FS=OFS=","} NR==FNR{arr=$2;next} $0 !~ "Documentation"{print $0;next} ... (2 Replies)
Discussion started by: kinmak
2 Replies

9. Shell Programming and Scripting

nawk -v to awk

hi, i have the command nawk -v i want to use it equivalent in awk? any help please :) (2 Replies)
Discussion started by: kamel.seg
2 Replies
Login or Register to Ask a Question