Note that there are some explanatory texts on larger screens.

plurals
  1. POPrinting Selected Lines in Large File
    text
    copied!<p>I am new to AWK.</p> <p>I have a large text file (>3GB). Like to use AWK line command to extract/print selected lines (line #62, #152 and 153) in that order and it iterates every 217 lines till end of record in file.</p> <p>Tried to search and learn from the net. Tried the below and it does not seem working,</p> <pre><code>awk '{(for (i=62; i&lt;=NR; i=i+217)||for (i=62; i&lt;=NR; i=i+217)||for (i=62; i&lt;=NR; i=i+217)); print}' file.txt </code></pre> <p>and</p> <pre><code>count=62||152||153 awk '{if (++count%217==0) print;}' file.txt </code></pre> <p>Could you assist to give me some pointers or lead me to any web which might be of help.</p> <p>I am using this <a href="http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt" rel="nofollow">http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt</a> to learn.</p> <p>rgds Saravanan K</p> <p><strong>Update #1 - 21 Sept 2012 - 10.40pm</strong></p> <p>Tried </p> <pre><code>awk 'NR == 62 || NR == 152 || NR == 153 || NR % 217 == 0 {print $0;}' file.txt </code></pre> <p>Able to print line #62, #152 and #153 but not all the following iterations e.g #(62+217), #(152+217) and #(153+217) and so on.</p> <p>Tried the below too, but it is not working well.</p> <pre><code>awk '(NR == 62 || NR == 152 || NR == 153) &amp;&amp; (((NR-62) % 217==0) || ((NR-152) % 217 ==0)|| ((NR-153) % 217==0)) {print $0;}' file.txt </code></pre> <p><strong>Update #2 - 21 Sept 2012 - 10.55pm -- CLOSED</strong> </p> <p>I tried rmunoz idea with some tweaking. It worked like a magic. Thanks for rmunoz, with this I close this topic</p> <pre><code>awk '(NR - 62) % 217 == 0 || (NR - 152) % 217 == 0 || (NR - 153) % 217 ==0 {print $0;}' file.txt </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload