print every nth line

2011-03-01 227 words 2 mins read

Some time back I was working with lot of data and wanted to analyze only the every 10 line sometimes and sometimes every 20th line. I had to keep doing these changes in vim or otherwise so finally I wrote a program to do this for me. If you need such a program then here it is:

  <td>
    <div class="text codecolorer">
      #!/bin/bash -<br /> #===============================================================================<br /> #<br /> #          FILE:  print_nth_line.sh<br /> #<br /> #         USAGE:  ./print_nth_line.sh<br /> #<br /> #   DESCRIPTION:  Print every nth line<br /> #<br /> #       OPTIONS:  ---<br /> #  REQUIREMENTS:  ---<br /> #          BUGS:  ---<br /> #         NOTES:  ---<br /> #        AUTHOR:   (),<br /> #       COMPANY:<br /> #       VERSION:  1.0<br /> #       CREATED:  12/08/2010 05:36:53 PM IST<br /> #      REVISION:  ---<br /> #===============================================================================<br /> <br /> if [ x"$1" == "x" ]<br /> then<br /> echo "Please provide the line numbers to print .. .ex 3 will print 3,6,9"<br /> exit -1;<br /> fi<br /> if [ x"$2" == "x" ]<br /> then<br /> echo "Please provide the filename"<br /> exit -2;<br /> fi<br /> awk 'temp++ { if ( temp % '$1' == 0) print $1};' $2
    </div>
  </td>
</tr>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Enhanced by Zemanta

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it