Today I had a situation where I had to search/grep for a specific line number in a file in linux. Here is the solution I found and thought it is worth sharing:
Uncompressed File:
Compressed File:
Above examples grep/search for line number 337930.
Uncompressed File:
cat test_file.csv | head -line_number | tail -1
cat test_file.csv | head -337930 | tail -1
cat test_file.csv | head -337930 | tail -1
Compressed File:
zcat test_file.gz | head -line_number | tail -1
zcat test_file.gz | head -337930 | tail -1
zcat test_file.gz | head -337930 | tail -1
Above examples grep/search for line number 337930.
Please add -A and -B as well , its also very helpful.
ReplyDeleteIt will print number of lines before and after matched content.