Posted By

blackthorne on 12/10/09


Tagged

head sed bc tail parsing blackthorne


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

blackthorne


Display a range of lines in a specified file


 / Published in: Bash
 

  1. Let's say you want to get all lines from 4 to 10 in the file /etc/passwd:
  2. sed -n '4,10p' /etc/passwd
  3.  
  4. Alternative:
  5. head -n 10 /etc/passwd | tail -n 6
  6. or
  7. FIRST_LINE=4; LAST_LINE=10; head -n $LAST_LINE /etc/passwd |tail -n `echo "$LAST_LINE - $FIRST_LINE"|bc`

Report this snippet  

You need to login to post a comment.