Monday, 6 August 2018

To print a specific line from a file


sed -n 5p <file>
You can get one specific line during any procedure. Very interesting to be used when you know what line you want.

Sample Output
> sed -n 5p test line 5 
> cat test line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 line 10

Print all lines between two line numbers

This command uses awk(1) to print all lines between two known line numbers in a file. Useful for seeing output in a log file, where the line numbers are known. The above command will print all lines between, and including, lines 3 and 6.

awk 'NR >= 3 && NR <= 6' /path/to/file


Print all lines between two line numbers
Print all lines between two line numbers This command uses sed(1) to print all lines between two known line numbers in a file. Useful for seeing output in a log file, where the line numbers are known. The above command will print all lines between, and including, lines 3 and 6. Show Sample

Output
sed -n '3,6p' /path/to/file

0 comments:

Post a Comment