Exclude First Line when awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exclude First Line when awk
# 1  
Old 06-22-2015
Exclude First Line when awk

Hi there,

Where do I add the
Code:
 !NR==1

into the awk statement such that it ignores the first line .

Code:
awk '/1.2 Install/ {P=0} /1.1 Apply/ {P=1} P {print FILENAME, $0} ' solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt

# 2  
Old 06-22-2015
Hello alvinoo,

Could you please try following and let me know if this helps.
Code:
 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

Last edited by RavinderSingh13; 06-22-2015 at 07:15 AM..
# 3  
Old 06-22-2015
You can just add

FNR == 1 {next} to skip first line, finally your command looks like this
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


Last edited by Akshay Hegde; 06-22-2015 at 08:17 AM..
# 4  
Old 06-22-2015
Hi,
try this,
Code:
awk 'NR>1{/1.2 Install/ {P=0} /1.1 Apply/ {P=1} P {print FILENAME, $0} }' solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt

# 5  
Old 06-22-2015
Quote:
Originally Posted by pravin27
Hi,
try this,
Code:
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
# 6  
Old 06-22-2015
Hey Akshay .. Thanks

Shorten code.

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

# 7  
Old 06-22-2015
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:-
Code:
NR The total number of input records seen so far.

FNR The input record number in the current input file.

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