Help with explanation of awk parameters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with explanation of awk parameters
# 1  
Old 09-27-2010
Help with explanation of awk parameters

Hello,

Would someone be able to tell me exactly how this command works please?

Code:
awk '!x[$0]++'

As usual any help much appreciated
# 2  
Old 09-27-2010
It eliminates matching lines by printing only lines which were not previously added to an array (x)
# 3  
Old 09-27-2010
Thanks Scott. I've been using it to remove blank lines from a file but I wondered what all the specific characters mean. IE:

!x
[$0]
++
# 4  
Old 09-27-2010
It will not only eliminate blank lines, but also nonempty duplicate lines. To delete blank lines this would be better:
Code:
awk '!/^$/'

# 5  
Old 09-27-2010
Hi.

It won't remove the first blank line - it only removes duplicate lines (blank or otherwise).

To remove all blank lines, the bartus11 solution is more suited.
# 6  
Old 09-27-2010
Or
Code:
awk NF

# 7  
Old 09-27-2010
Or
Code:
grep .

LOL
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Web Development

Apache rewrite/redirect parameters explanation

hi what is the meaning of the below code, please explain in details RewriteRule '^/(.*)$1$2/?' (1 Reply)
Discussion started by: raghur77
1 Replies

2. Shell Programming and Scripting

Explanation of FNR in this awk script

To merge mutiple *.tab files as: file1.tab rs1 A A rs2 A A rs3 C C rs4 C Cfile2.ind rs1 T T rs2 T T rs3 G G rs4 G Gand file3.tab rs1 B B rs2 B B rs3 L L rs4 L LOutput: file1.tab file2.tab file3.tab AA TT BB AA TT BB CC GG LL CC GG ... (4 Replies)
Discussion started by: yifangt
4 Replies

3. Shell Programming and Scripting

Explanation of print statement - awk

Hi, i'm just after a simple explanation of how the following awk oneliner works. gawk -F"," '{for(i=m;i<=n;i++)printf "%s" OFS,$i; print x}' m=1 n=70 OFS=, input.csv > output.csv In particular i'm trying to understand how the two print statements work? How is the "x" variable being assigned... (3 Replies)
Discussion started by: theflamingmoe
3 Replies

4. Shell Programming and Scripting

awk explanation

Hello, I have recently come across this awk program. Can some one shed some light on what is taking place. awk '{!a++}END{for(i in a) if ( a >10 ) print a,i }' $FILE Best Regards, jaysunn (1 Reply)
Discussion started by: jaysunn
1 Replies

5. Shell Programming and Scripting

Explanation for printf string in awk

hi all can any one help me to understand this bdf -t vfxs | awk '/\//{printf("%-30s%-10s%-10s%-10s%-5s%-10s\n",$1,$2,$3,$4,$5,$6)}' i want to understand the numbers %-30S% (4 Replies)
Discussion started by: maxim42
4 Replies

6. Shell Programming and Scripting

passing parameters using awk

Hi, The below script is working fine awk1.sh ======= awk BEGIN { FS="|" } FNR==NR { f1=$2; next } $1 in f1 && $2 =="xx" && $1 == "DAILY_JOB" {print $3} awk -f awk1.sh a.txt b.txt--Its working fine . When passing parameters its not working .Any help it should be appereciated. ... (4 Replies)
Discussion started by: akil
4 Replies

7. Shell Programming and Scripting

AWK alias with parameters

Hello, How can I make an alias of an AWK one liner that prints specific lines from a file like below? # from a command like this: awk 'NR == 100, NR == 150' file.cfg The alias I want to make should work like this(I guess): <alias_command> <file.cfg><start_line><end_line> So the... (1 Reply)
Discussion started by: majormark
1 Replies

8. Shell Programming and Scripting

awk - printing parameters

Hello I've got a script that takes 2 parameters. id and f. id is a user id and f is a file. I want to print this id on the first line and then the file. how can this be done? thanks (3 Replies)
Discussion started by: jacma
3 Replies

9. Shell Programming and Scripting

AWK deifnition and some small code explanation

Could someone give me a quick simple explanation for the AWK command. And also help me to explain the code i have made. I have made some general comments about it myself. I was wondering if people could help me with the rest: awk -F'' 'END { fmt = "%-20s\t%s\t%s\n" ... (0 Replies)
Discussion started by: amatuer_lee_3
0 Replies

10. Shell Programming and Scripting

AWK explanation

Hi, Could anyone please explain why we have arr=1 - what does this statement do? awk -F\; 'FNR==NR{arr=1;next};$3 in arr' core.txt gmrd.txt Any help appreciated (2 Replies)
Discussion started by: penfold
2 Replies
Login or Register to Ask a Question