Skip to content
Advertisement

How can I print a specific range of lines from a file in linux? [closed]

If I have a file with 100,000 lines, how can I print lines in a specified range, such as lines 15010 to 15020?

Advertisement

Answer

sed:

$ sed -n '15010,15020p' input.txt

awk:

$ awk '15010<=NR && NR <=15020' input.txt

head/tail:

$ head -n 15020 input.txt | tail -n $((15020-15010+1))
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement