So this is for homework, but I will not be asking the specific homework question.
I need to use head and tail to grab different sets of line from one file. So like lines 6-11 and lines 19-24 and save them both to another file.
I know I can do this using append such as
head -11 file|tail -6 > file1; head -24 file| tail -6 >> file1.
But I don't think we are supposed to.
Is there a specific way I could combine the head and tail commands and then save to the file?
Best Answer
You can do it with
head
alone and basic arithmetic, if you group commands with{ ... ; }
using a construct likewhere all commands share the same input (thanks @mikeserv).
Getting lines 6-11 and lines 19-24 is equivalent to:
So, basically, you would run: