How do I print specific line numbers in a file using awk?

Using awk you can specify which lines you print. If you wanted to print lines 1-10, you could do this:

awk ‘NR<=10' /path/to/my/file Another way to specify which lines to print is like this: awk 'NR==1 || NR==2' /path/to/my/file This would only print lines 1 and 2. The || denotes or. If you have other requirements, you can use && like this: awk 'NR<=10 && NF>2′ /path/to/my/file

This would print lines 1-10 if they have more than 2 fields (NF).

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top