pseudo code:
In awk expresions that result in non-zero equate to true for more clarity we could rewrite as follows:
Also the default action in awk is to print the current line, the following is also the same:
Edit:
Took a while to type my response so above probably repeats what was already said. To answer you question yes the {} are necesary awk consists of a number of
expression { action }
pairs. Expression can be null in which case action is always executed, otherwise expression needs to equate to true before the action(s) are performed.
Special expressions BEGIN and END equate to true before and after the file is processed.
Variables are null (or zero) before being assigned, no arrays are used here (arrays have [])
Last edited by Chubler_XL; 10-20-2010 at 03:22 PM..
Does "p" has a special meaning or is it a random choice of variable name?
Could you please comment your code ?
default NF is 1 ?
so p=p+1 ?
what is the default value of p ? p=1 ?
so that would make start to print$0 from line 2 ?
NF refer to the number of field of the line (which is 1 by default unless another separator is set ) or does it refer to the field number/index (the default field is a line )?
Could this also be written like this (is it equivalent)?
I am a little confuse between NF and NR can someone clarify a little (ok a record is supposed to be composed of field so NF should refer to something inside NR...)
By default, a line is a field ? or a record ? or both ? (1 record of 1 field ?)
It is a random variable name. I could also have used:
The value for NF varies per line. When there is an empty line then NF (number of fields) equals zero, hence the variable stays 0 for the first few lines that are empty. The value of the variable determines if the record gets printed. The default record is a line. NR is something else, that is the line number.
Last edited by Scrutinizer; 10-21-2010 at 05:52 AM..
This User Gave Thanks to Scrutinizer For This Post:
Ok i got it
wasn't aware x would be kept between 2 line read (i though the condition was evaluated for each line so that x would be reset every time a line was read), so i wasn't understanding the use of += instead of = but i got it now (otherwise the empty line that are not the first one wouldn't have been printed...
Hello,
I am trying to remove everything coming after empty line under ubuntu14.04.
How may I do it?
file:
aaa
020390
bb00id3
c03wisi
209dl
x092sia
0290s
I expect:
aaa
020390
bb00id3
c03wisi (3 Replies)
Hi All,
I have a file.txt which seems like having three lines.
wc -l file.txt
3 file.txt
In fact, once it is open in text editor, this file has four lines where the last line is empty. how can i delete this last empty line of the file.txt? I tried the codes below so far but they... (6 Replies)
Hi All,
I have a very huge file (4GB) which has duplicate lines. I want to delete duplicate lines leaving unique lines. Sort, uniq, awk '!x++' are not working as its running out of buffer space.
I dont know if this works : I want to read each line of the File in a For Loop, and want to... (16 Replies)
Hi
What I'm trying to do is delete every blank line upto a certain number, so for instance I only want to delete the first 4 empty lines within a file, I know how to delete every line with:
sed '/^$/d'
But I can't figure out how to limit it to only the first 4 occourances
I though it... (5 Replies)
hi,
I'd like to ask you if you can help me with such surely easy thing - I have some data and need to plot them. I have txt of data in two columns, tab separated, but some second columns are empty. like
1```` 2
1.2``
3```` 2
4.44`
5`````
6.1```1
how can I erase all the lines... (2 Replies)
abc#
abc#this is a test
abc#this is a test to delete
abc#
xyz#
xyz#this is a test two
xyz#
In the above example '#' is common. How to do delete the emply lines. In specific to observe the output as:
abc#this is a test
abc#this is a test to delete
xyz#this is a test two
.
.
.
. (5 Replies)
Hi,
I have an dir which has 50K file, some of them are empty. I want to delete the empty file from the dir. I am planning to use the following command.
ls -l | grep " 0 " | awk '{print $9}'
I can copy this to an file and then how do I use this file to delete the empty files.... Any help... (2 Replies)
Hi,
I need to delete the lines with empty name.
What is the best way to do it?
Thanks a lot for your help!
EMID MMDDYY HOURS JOB EMNAME
0241 051605 11.40 52062 someone
0520 051605 10.63 52062
0520 051605 10.66 52062
0520 051605 10.65 52062 (3 Replies)