I have a large file which contains tables of different tab separated data. The different tables are separated by a blank line.
I have the line number of the start of a particular table and I need to retrieve the whole table.
How can I use grep (or something similar) to get the line number of the next blank line after a specific line number?
Use
sedfor this, this should do the trick:Just replace the first number before the comma, in this case
1with the line number, demo to print each table from a given line number:Using the
-noption to turn of default printing of every line and thepflagsedprints from the line number to the first line that matches the regexp where:Using the format
sed -n 'A,Bp'whereAandBcan be either lines numbers or regular expression you can print subsections of files easily.To print just the line number of the next blank line with
seddo:Or just printing where all the blanks lines are
Getting the next blank line number with
awkdoesn’t require usingtail:If it makes it clearer for you, you can pass a variable in with
awkusing-v