Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing every nth line

Status
Not open for further replies.

ng1

Technical User
Aug 22, 2007
39
0
0
US
I am using a sed statement to print every nth line. In the example below, I am printing every 15th line starting at line 15.
What if I want to print every 150th line? Is there a way in awk or sed to not have to type out all the n's? It would not be practical to type 149 n's.




sed -n '15,${p;n;n;n;n;n;n;n;n;n;n;n;n;n;n;}' FILE
 
I got it from another post. This works:

awk 'NR %150==0' FILE

Now I am looking for a way to delete every 150th line.
 
Daaaaaaa

awk 'NR %150!=0' FILE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top