Hi there,
Where do I add the
!NR==1
into the awk statement such that it ignores the first line .
awk '/1.2 Install/ {P=0} /1.1 Apply/ {P=1} P {print FILENAME, $0} ' solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt
Hi there,
Where do I add the
!NR==1
into the awk statement such that it ignores the first line .
awk '/1.2 Install/ {P=0} /1.1 Apply/ {P=1} P {print FILENAME, $0} ' solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt
Hello alvinoo,
Could you please try following and let me know if this helps.
awk '/1.2 Install/ {P=0} /1.1 Apply/ {P=1} P && NR>1{print FILENAME, $0} ' solarisdbsummary.txt solaris_websummary.txt
Thanks,
R. Singh
You can just add
FNR == 1 {next} to skip first line, finally your command looks like this
awk 'FNR == 1 {next}/1.2 Install/ {P=0} /1.1 Apply/ {P=1} P {print FILENAME, $0} ' solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt
Hi,
try this,
awk 'NR>1{/1.2 Install/ {P=0} /1.1 Apply/ {P=1} P {print FILENAME, $0} }' solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt
Pravin this produces ^ syntax error
Hey Akshay .. Thanks
Shorten code.
awk 'NR>1 && /1.1 Apply/ {print FILENAME, $0}' solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt
Also as Akshay had pointed out if multiple input files, FNR should be used instead of NR to skip first record in each input file:-
NR The total number of input records seen so far.
FNR The input record number in the current input file.
I wonder if suppressing the FNR==1 (first line of each file) does have an effect because
awk '/1.2 Install/ {P=0} /1.1 Apply/ {P=1} P {print FILENAME, $0}'
prints the block between 1.1 Apply and 1.2 Install .
In another thread I have already suggested to move the P condition before the 1.1 Apply (block start) condition
awk '/1.2 Install/ {P=0} P {print FILENAME, $0} /1.1 Apply/ {P=1}'
so it does not print the 1.1 Apply line.
May I point a fact?
This snippet does not, cannot, replace the original snippet. They are not equivalent.
The previous will print only, and ONLY, records that match the /1.1 Apply/ if is not the first record of the first file.
On the other hand:
awk 'FNR == 1 {next}/1.2 Install/ {P=0} /1.1 Apply/ {P=1} P {print FILENAME, $0} ' solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt
This one will start printing any records once that the match /1.1 Apply/ is found until it finds again the match /1.2 Install/, skipping the first record of every file.
Hi All,
Thanks for helping, make tag as resolved
awk '/2.1 Disable/ {P=0} P {print $0} FNR==1{printf("From file %s:\n", FILENAME)} /1.3 Install/ {P=1}' solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt
echo -e "2.1 Disable standard services if possible"
From file solarisappsummary.txt:
STATE STIME FMRI
online Feb_05 svc:/network/ssh:default
From file solarisdbsummary.txt:
STATE STIME FMRI
online Dec_29 svc:/network/ssh:default
From file solaris_websummary.txt:
STATE STIME FMRI
online Jun_05 svc:/network/ssh:default
awk '{getline;print}' file
$ cat numbers
line one
line two
line three
line four
line five
line six
line seven
line eight
line nine
line ten
$ awk '{getline;print}' numbers
line two
line four
line six
line eight
line ten
thanks Aia for pointing this out. the getline should present in the BEGIN block...