awk, ignore first x number of lines.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk, ignore first x number of lines.
# 1  
Old 05-19-2008
awk, ignore first x number of lines.

Is there a way to tell awk to ignore the first 11 lines of a file?? example, I have a csv file with all the heading information in the first lines. I want to split the file into 5-6 different files but I want to retain the the first 11 lines of the file.

As it is now I run this command:

Code:
cat something.csv | nawk '$2 = /servername/' >> something-new.csv

It cuts off the first 11 lines... Right now im just doing two steps to create the file running sed 11q > something-new.csv then running the above command appending something-new.csv. Is there a way to do that with just nawk so I can eliminate the sed command?
# 2  
Old 05-19-2008
Quote:
Originally Posted by trey85stang
Is there a way to tell awk to ignore the first 11 lines of a file?? example, I have a csv file with all the heading information in the first lines. I want to split the file into 5-6 different files but I want to retain the the first 11 lines of the file.

As it is now I run this command:

Code:
cat something.csv | nawk '$2 = /servername/' >> something-new.csv

It cuts off the first 11 lines... Right now im just doing two steps to create the file running sed 11q > something-new.csv then running the above command appending something-new.csv. Is there a way to do that with just nawk so I can eliminate the sed command?

Maybe like this:

cat -n something| awk '$1>11 && (the conditions you like)

cat -n adds to the first coloumn the number of line.

Regards
# 3  
Old 05-19-2008
Quote:
Originally Posted by elthox
Maybe like this:

cat -n something| awk '$1>11 && (the conditions you like)

cat -n adds to the first coloumn the number of line.

Regards
sounds like that will work, then I can just exclude the first column on the print out with awk.

Thanks for the help!
# 4  
Old 05-19-2008
Quote:
Originally Posted by elthox
Maybe like this:

cat -n something| awk '$1>11 && (the conditions you like)

cat -n adds to the first coloumn the number of line.

Regards
OR:
Code:
awk 'NR>11' file

# 5  
Old 05-19-2008
or u can try

awk '{ NR <= 11 {next}
{ ur statments }' <filename>
# 6  
Old 05-19-2008
Quote:
Originally Posted by Klashxx
OR:
Code:
awk 'NR>11' file

Yeah Klashxx....this looks more elegant.
# 7  
Old 05-21-2008
hmm, Ive tried these examples. the first 11 are not printed in any of the above statements. Maybe I asked incorrectly? I am looking to have lines 1-11 printed regardless of any parameters I pass with awk.

Perhaps my two command way is the best way to do this?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script using awk to find and replace a line, how to ignore comment lines

Hello, I have some code that works more or less. This is called by a make file to adjust some hard-coded definitions in the src code. The script generated some values by looking at some of the src files and then writes those values to specific locations in other files. The awk code is used to... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

2. Shell Programming and Scripting

awk - Skip x Number of Lines in Counter

Hello, I am new to AWK and in UNIX in general. I am hoping you can help me out here. Here is my data: root@ubuntu:~# cat circuits.list WORD1 AA BB CC DD Active ISP1 ISP NAME1 XX-XXXXXX1 WORD1 AA BB CC (9 Replies)
Discussion started by: tattoostreet
9 Replies

3. Shell Programming and Scripting

awk to output lines less than number

I am trying to output all lines in a file where $7 is less than 30. The below code does create a result file, but with all lines in the original file. The original file is tab deliminated is that the problem? Thank you :). awk 'BEGIN{FS=OFS=","} $7 < 30 {print}' file.txt > result.txt... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

awk code to ignore the first occurence unknown number of rows in a data column

Hello experts, Shown below is the 2 column sample data(there are many data columns in actual input file), Key, Data A, 1 A, 2 A, 2 A, 3 A, 1 A, 1 A, 1 I need the below output. Key, Data A, 2 A, 2 A, 3 A, 1 A, 1 A, 1 (2 Replies)
Discussion started by: ks_reddy
2 Replies

5. Shell Programming and Scripting

Awk number of lines

How do I get the last NR of a csv file? If I use the line awk -F, '{print NR}' csvfile.csv and there are 42 lines, I get: ... 39 40 41 42 How do I extract the last number, which in this case is 42? ---------- Post updated at 11:05 AM ---------- Previous update was at 10:57 AM... (1 Reply)
Discussion started by: locoroco
1 Replies

6. Shell Programming and Scripting

How to (n)awk lines of CSV with certain number of fields?

I have a CSV file with a variable number of fields per record. How do I print lines of a certain number of fields only? Several permutations of the following (including the use of escape characters) have failed to retrieve the line I'm after (1,2,3,4)... $ cat myfile 1,2,3,4 1,2,3 $ # Print... (1 Reply)
Discussion started by: cs03dmj
1 Replies

7. Shell Programming and Scripting

How do I print out lines with the same number in front using awk?

Hi, I need help in printing out the dates with the largest value in front of it using awk. 436 28/Feb/2008 436 27/Feb/2008 436 20/Feb/2008 422 13/Feb/2008 420 23/Feb/2008 409 21/Feb/2008 402 26/Feb/2008 381 22/Feb/2008 374 24/Feb/2008 360... (7 Replies)
Discussion started by: SIFA
7 Replies

8. Shell Programming and Scripting

awk - Counting number of similar lines

Hi All I have the input file OMAK_11. OMAK 000002EXCLUDE 1341 OMAK 000002EXCLUDE 1341 OMAK 000002EXCLUDE 1341 OMAK 000003EXCLUDE 1341 OMAK 000003EXCLUDE 1341 OMAK 000003EXCLUDE ... (8 Replies)
Discussion started by: dhanamurthy
8 Replies

9. Shell Programming and Scripting

Limit of number of lines for awk and sed.

Hi, I'm using awk and sed to extract some data out from a text file. The text file consists of data over a million (prolly millions) of lines. Question: Is there a limit of number of lines for awk and sed? Thanks in advance. (2 Replies)
Discussion started by: 60doses
2 Replies

10. Shell Programming and Scripting

How to print number of lines with awk ?

Can some body tell me how to print number of line from a particular file, with sed. ? Input file format AAAA BBBB CCCC SDFFF DDDD DDDD Command to print line 2 and 3 ? BBBB CCCC And also please tell me how to assign column sum to variable. I user the following command it... (1 Reply)
Discussion started by: maheshsri
1 Replies
Login or Register to Ask a Question