How to Extracting specific lines from a large (compressed) text file?

How to read specific lines from large text file?

You can use sed command to read lines from the large text file. Let say that you want to read line 2,4 and 6 from the large text file. Try following code:

# prints line 2,4 and 6 from sample.txt file
sed -n '2p;4p;6p' sample.txt

Read specific lines from gzip file

# prints line 4 and 6 and exit the file at line 7
# very useful to avoid reading whole file and exit and specific line
zcat database.sql.gz | sed -n '4p;6p;7q'

# or you can use
gunzip -c file.gz | sed -n '4p;6p;7q'

read from specific line

# start reading from 100th line
less +100g bigfile.txt