otherdata
otherdata
start_data
one
two
three
four
end_data
otherdata
otherdata
The resulting output should just be:
one
two
three
four
This looked like a job for sed to me:
sed -n '/start_data/,/end_data/{1d;$d;p}' myfile
Did not work. First line was deleted, but not the last line! (for no reason that I could explain by logic so far)
OK, so let's try the ugly way:
sed -n '/start_data/,/end_data/{/start_data\|end_data/!p}' myfile
Fair enough, this works. But I'd like to make the shorter method work as well, as the resulting output will always contain the two patterns on first and last line, since we're only extracting the data in between.
Why does sed choke at the attempt of combining the 1d and $d statements in curly braces?
start_dataandend_datain your output or don't you? – G-Man Says 'Reinstate Monica' Jun 18 '15 at 05:44sedstatement that does adon first and last line will do. – syntaxerror Jun 18 '15 at 08:47sedFAQ 4.24 – Stéphane Chazelas Jun 18 '15 at 09:22>>to each line, but of course, you can use-nand print them instead or whatever operation you want to perform on the range. – Stéphane Chazelas Jun 18 '15 at 09:54