AWK - Hard to understand for me


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers AWK - Hard to understand for me
# 22  
Old 03-26-2012
OK in that case, try this:
Code:
awk -F\| '!/^#/ && !A[$4]++{print $4}' infile

This User Gave Thanks to Scrutinizer For This Post:
# 23  
Old 03-27-2012
Thank you sooo much Scrutinizer.

It has worked perfectly the way I wanted... kudos to you.

Can you please explain me the above command, I am bit new to awk.

Thanks Again, Ambar
# 24  
Old 03-27-2012
The difference with the earlier explanation given by itkamaraj is !A[$4]++ . This means if the value in array A of element is zero (if NOT (!) it is 1 or more) then perform the action in curly brackets. After the comparison the value of the element is incremented by 1, so the next time the same $4 is encountered later in the file, the expression evaluates to 0 (since the array element is not 1 and it is negated by the ! ), so the second time and any time after that, the action in curly brackets is not performed (in this case {print $4} )
This User Gave Thanks to Scrutinizer For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help understand awk command

Help understand awk command This command converts the column values to rows. Command: awk -s1=" " '{S=S?S OFS s1 $0 s1:s1 $0 s1} END{print S}' OFS=, Input_file Example: 1 2 3 is converted to: 1, 2, 3 Can anyone please help me understand this command? Please use code tags when... (1 Reply)
Discussion started by: mohan44
1 Replies

2. Shell Programming and Scripting

(hard one) awk, copy matching 2 col & 10-12 rows, is it possible?

Hey guys, my first post here. I'm trying to use awk to copy all matching paragraphs from one file The file looks like this : Test Case Number 990990003099 Card Type CCCC Transaction Type Sale Entry Mode Keyed Account Number 4099562299219923 Transaction Amount 78.88 Description lorem... (2 Replies)
Discussion started by: awkawed
2 Replies

3. UNIX for Dummies Questions & Answers

Unable to understand awk script.

Hi below is the samll awk script which i am not able to understand properly. here a bit confusion in 2nd line for me 1. why *\ is not used before . in second line as it was used in first line *\$*\. */ 2. why always \ is used in every first line 3. is there any specific meaning... (9 Replies)
Discussion started by: scriptor
9 Replies

4. Shell Programming and Scripting

awk doesn't understand 'read' statement!!!

While working on awk programming, i found that it doesn't understand 'read' statement. Then what's the use of 'continue' and 'break' statement in awk. For ex: awk '{k=1; while (k<10) {print $0; k++}}' emp.lst Now, please say if I want to put the logic that after priting 1 line, it will ask for... (13 Replies)
Discussion started by: ravisingh
13 Replies

5. Shell Programming and Scripting

Don't understand AWK asort behaviour

Hello, I have the following script : BEGIN { print "1 ***"; split("abc",T,""); T="e"; T="z"; T="y"; for (i in T) printf("%i:%s ",i,T); print ""; for (i=1; i<=length(T); i++) printf(T); print "" print "2 ***"; asort(T,U); for (i in U) printf("%i:%s ",i,U); ... (3 Replies)
Discussion started by: jgilot
3 Replies

6. Shell Programming and Scripting

Need help to understand Awk code.

Hi Guys, Can someone please explain this code to me. I could figure out it's adding and comparing two fields but I am not sure which ones. sort -t"|" -k3.1 /tmp/mpcashqc.xtr| awk -F"|" '{CHECKAMT+=$3;BATCHTOT=$4;\ items++}END{for(i in CHECKAMT) if (CHECKAMT!=BATCHTOT)... (6 Replies)
Discussion started by: nua7
6 Replies

7. Shell Programming and Scripting

Don't understand how RS functions in awk

I learn using RS in awk to extract portion of file in this forum which is wonderful solution to the problem. However, I don't understand how exactly it operates. I don't quite understand the mechanism behind how searching for /DATA2/ can result in extracting the whole section under "DATA2" ... (3 Replies)
Discussion started by: joe228
3 Replies

8. UNIX for Dummies Questions & Answers

unable to understand a awk code

i am not able to understand the following code for awk: $awk -F"|" '{ kount++} >END { for (desig in kount) > print desig,kount }' emp.list the input file i.e. emp.list is :: 3432| p.k.agrwal |g.m |sales 4566|g.l.sharma |director|production 3433|r shah | g.m | production... (1 Reply)
Discussion started by: streetfi8er
1 Replies

9. UNIX for Dummies Questions & Answers

Unable to understand associative nature of awk arrays

About associative nature of awk arrays i'm still confused, not able to understand yet how array element can be accessed based on a string, I got one example at gawk manual to illustrate associative nature of awk arrays, it goes here: Codeawk ' # Print list of word frequencies { for (i = 1;... (3 Replies)
Discussion started by: nervous
3 Replies

10. Filesystems, Disks and Memory

The best partitioning schem for a 250GB Sata hard drive & a 75GB SCSI hard drive

Hi I have 2 75GB SCSI hard drives and 2 250GB SATA hard drives which are using RAID Level 1 respectively. I wana have both FTP and Apache installed on them as services. I'm wondering what's the best partitioning schem? I wana use FC3 as my OS, so, I thought I can use the 75GB hard drive as the /... (0 Replies)
Discussion started by: sirbijan
0 Replies
Login or Register to Ask a Question