[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I print every 10th line of a file from UNIX shell (grep, awk, sed) ???

Posted on 2008-11-14
4
Medium Priority
?
1,140 Views
Last Modified: 2013-12-26
How do I print every 10th line of a file from UNIX shell.

I need a grep/awk/sed command which can help me print every nth line of a huge netflow data which I am trying to sample
0
Comment
Question by:Shivam_p
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
peter991 earned 80 total points
ID: 22958308
If you want the first line as nr one and then count 10 steps ahead and print every 10:th line.

$> sed -n '1,${p;n;n;n;n;n;n;n;n;n;}' file

If you want to start at line 10.

$> sed -n '10,${p;n;n;n;n;n;n;n;n;n;}' file
0
 
LVL 85

Expert Comment

by:ozo
ID: 22958323
awk 'NR%10==0'  file
0
 

Author Closing Comment

by:Shivam_p
ID: 31516713
Thanks buddy.... that was precisely I was looking for !!
0
 
LVL 85

Expert Comment

by:ozo
ID: 22958334
If you want to start at line 1

awk 'NR%10==1'
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question