Exclude First Line when awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exclude First Line when awk
# 8  
Old 06-22-2015
I wonder if suppressing the FNR==1 (first line of each file) does have an effect because
Code:
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
Code:
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.
# 9  
Old 06-22-2015
Quote:
Originally Posted by pravin27
Hey Akshay .. Thanks

Shorten code.

Code:
awk 'NR>1 && /1.1 Apply/ {print FILENAME, $0}'  solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt

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:

Code:
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.
# 10  
Old 06-22-2015
Hi All,

Thanks for helping, make tag as resolved

Code:
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"


Code:
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

# 11  
Old 06-23-2015
Code:
 awk '{getline;print}' file[s]

# 12  
Old 06-23-2015
Quote:
Originally Posted by Khanaza
Code:
 awk '{getline;print}' file[s]

Quote:
"I do not think it means what you think it means"
Code:
$ 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

# 13  
Old 06-23-2015
thanks Aia for pointing this out. the getline should present in the BEGIN block...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

awk online to exclude rows

Hello, I have 3 columns like shown below: 1 1800 1900 2 1765 1900 3 1654 2054 4 1326 1499 5 1540 1765 I want only those rows where column 2 and column 3's values don't fall within 1800-1900 both inclusive. My output should only be: 4 1326 1499 5 1540 1765 Is there a quick awk... (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

2. UNIX for Dummies Questions & Answers

Exclude new line character while searching

Hi, I have a log file and want to search "0.48976360737438795" with excluding new line character. Currently i am using the following command: cat LogFile.log | tr -d '\n' | grep '0.48976360737438795' This command giving me the response if file size is small but if i am using a big file... (11 Replies)
Discussion started by: ankit jain
11 Replies

3. Shell Programming and Scripting

AWK exclude first and last record, sort and print

Hi everyone, I've really searched for a solution to this and this is what I found so far: I need to sort a command output (here represented as a "cat file" command) and from the second down to the second-last line based on the second row and then print ALL the output with the specified section... (7 Replies)
Discussion started by: dentex
7 Replies

4. Shell Programming and Scripting

exclude blank line

hi, how can i exclude blank line along with #, in the below command. crontab -l|grep -v "^#" |wc -l thx (3 Replies)
Discussion started by: bang_dba
3 Replies

5. Shell Programming and Scripting

Perl exclude directories in command line

Hi, I use find command to list all the files in a directory and its sub-directories, but the problem is to exclude certain directories during search. Can i give the directory names in command line to skip them and search rest of the directories? For example i have directories: test ../test1... (1 Reply)
Discussion started by: nmattam
1 Replies

6. Shell Programming and Scripting

Have to exclude the first and last line of the file : help me

hi , i am very new to perl . scriptting.. pllease can any one help me ...pleaseeeeeee i ll have a file which look likes 123 |something |567 456 |welcome |789 457 |inboxpost |790 . . 123 |something |567 i have to execute all the lines in the file except the first and the... (14 Replies)
Discussion started by: vishwakar
14 Replies

7. Shell Programming and Scripting

awk and sed, how to exclude certain characters

Hello everyone: I have ran into this a few times now where my skills are just not up to snuff when it comes to Unix. So, I came here to find some beard stroking Unix wizard to help me. Basically, I am using OS X 10.5 in large scale at work and sometimes I have to run some custom reports. ... (5 Replies)
Discussion started by: tlarkin
5 Replies

8. Shell Programming and Scripting

how to exclude the header in shell script using awk

Hello Everyone In my shell script, I am retrieving the cluster ID and node number of an LPAR using the following command - lsclcfg -l This command's output looks as follows - CLUSTER_NAME CLUSTER_ID NODE_NR sch1h004 6104567 3 I want to store only the... (3 Replies)
Discussion started by: gates1580
3 Replies

9. UNIX for Dummies Questions & Answers

exclude columns with a matching line pattern

Hi , I have 5 columns total and am wanting to search lines in columns 3-5 and basically grep -v patterns that match 'BBB_0123' 'BVG_0895' 'BSD_0987' Does anyone know how to do this? I tried combining grep -v with grep -e but, it didn't work. Thanks! (5 Replies)
Discussion started by: greptastic
5 Replies

10. Shell Programming and Scripting

exclude a line

Hi, thanks for your help. I wrote this script : # ! /bin/sh file=snapshot.txt cat $file | while read line ; do { myvariable=`grep "Nombre de ROLLBACK internes" |sed 's/.*.=//'` echo $myvariable } done It looks in a file "snapshot.txt" for the lines containing "Nombre de ROLLBACK... (3 Replies)
Discussion started by: big123456
3 Replies
Login or Register to Ask a Question