Display a range of lines in a specified file


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.