AWK-grep from line number to the end of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK-grep from line number to the end of file
# 1  
Old 03-31-2012
AWK-grep from line number to the end of file

Does anyone know how to use awk to act like grep from a particular line number to the end of file? I am using Solaris 10 and I don't have any GNU products installed.

Say I want to print all occurrences of red starting at line 3 to the end of file.

EXAMPLE FILE:

red
green
red
red
yellow
green

So the ouput should be:
red
red
# 2  
Old 03-31-2012
Code:
awk 'NR>=3 && /red/' infile

This User Gave Thanks to kevintse For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

Grep pattern after specific line number in a file

Hi guys, I am running a while loop in a script ro read a file line by line. Now I want to run a grep only on the lines below the line I am that is being read by the while loop. Eg: If my while loop is on line 4 of the file, the grep only runs below line 4 and does not include line 1,2... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

3. Shell Programming and Scripting

Grep start and end line of each segments in a file

Cat file1 -------- ---------- SCHEMA.TABLE1 insert------- update----- ------------- ---------- SCHEMA.TABLE2 insert------- update----- ----------- ------------ SCHEMA.TABLE3 insert------- update----- ------------ grep -n SCHEMA > header_file2.txt (2 Replies)
Discussion started by: Veera_V
2 Replies

4. Shell Programming and Scripting

adding line number to *end* of records in file

Given a file like this: abc def ghi I need to get to somestandardtext abc1 morestandardtext somestandardtext def2 morestandardtext somestandardtext ghi3 morestandardtext Notice that in addition to the standard text there is the line number added in as well. What I conceived is... (4 Replies)
Discussion started by: edstevens
4 Replies

5. Shell Programming and Scripting

Help on Sed/awk/getting line number from file

I Have file1 with below lines : #HostNameSelection=0 :NotUsed #HostNameSelection=1 :Automatic #HostNameSelection=3 :NotForced I have file2 which has similar lines but with different values I want to copy the changes from file1 to file2 ,line by line only if line begins with '#'. for... (7 Replies)
Discussion started by: mvr
7 Replies

6. Shell Programming and Scripting

Grep from a starting line till the end of the file

Hi Folks, I got to know from this forums on how to grep from a particular line say line 6 awk 'NR==6 {print;exit}' But how do i grep from line 6 till the end of the file or command output. Thanks, (3 Replies)
Discussion started by: Mr. Zer0
3 Replies

7. Shell Programming and Scripting

awk script: print line number n of another file

Hi, I wrote an awk script to analyse file A. I call the script with files A and B. File A has lines like: 000000033100001 000000036100001 000000039100001 The first 9 characters are interpreted as a line number; for each line number found I want to output this line number of file B. ... (13 Replies)
Discussion started by: kpg
13 Replies

8. Shell Programming and Scripting

To add a number at the end of the line

Hi Folks, Using the Vi, how can I add a numbers at the end of the line. For eg: I have the numbers in the file as: 58.125.33 22.58.68 25.144.225 114.25.38 I need to add .0/8 at the end of all the line. So, it should be like 58.125.33.0/8 22.58.68.0/8 25.144.225.0/8 114.25.38.0/8 (6 Replies)
Discussion started by: gsiva
6 Replies

9. Shell Programming and Scripting

Number a list at end of line using 'sed'

Hi All I have a script which has produced a list, I have used 'sed' to number my list, but i want to list at end of line with the first line starting at zero (0) and brackets round it ie My List i want Hello (0) this (1) day (2) can (3) be (4) sed '/./=' filename | sed '/./N; s/\n/) /'... (5 Replies)
Discussion started by: chassis
5 Replies

10. Shell Programming and Scripting

Select matches between line number and end of file?

Hi Guys/Gals, I have a log file that is updated once every few seconds and I am looking for a way to speed up one of my scripts. Basically what I am trying to do is grep through a text file from start to finish once. Then each subsequent grep starts at the last line of the previous grep to... (4 Replies)
Discussion started by: Jerrad
4 Replies
Login or Register to Ask a Question