Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a simple way I can echo a file, skipping the first and last lines? I was looking at piping from head into tail, but for those it seems like I would have to know the total lines from the outset. I was also looking at split, but I don't see a way to do it with that either.

share|improve this question

3 Answers 3

up vote 49 down vote accepted

Just with sed, without any pipes :

sed '1d;$d' file.txt

NOTE

  • 1 mean first line
  • d mean delete
  • ; is the separator for 2 commands
  • $ mean last line
share|improve this answer

Try this:

tail -n +2 file.txt | head -n -1

doing it the other way round, works the same, of course:

head -n -1 file.txt | tail -n +2
share|improve this answer
tail -n +2 file.txt | head -n -2 

no start no end just clear road

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.