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

Posted on 2008-11-14
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
Question by:Shivam_p
    LVL 6

    Accepted Solution

    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
    LVL 84

    Expert Comment

    awk 'NR%10==0'  file

    Author Closing Comment

    Thanks buddy.... that was precisely I was looking for !!
    LVL 84

    Expert Comment

    If you want to start at line 1

    awk 'NR%10==1'

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. Please see for the updated article. It is avail…
    FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    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…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now