LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sed Problem (https://www.linuxquestions.org/questions/linux-newbie-8/sed-problem-438912/)

Hydrap 04-26-2006 03:23 AM

Sed Problem
 
I wnat to use sed to change delete some lines in a file, but I dont know how to write the sed script.
The file is:

john
2004
hello world
hello
2005

peter
2004
goodbye
2005

My target is to delete the line between 2004 and 2005. However when I write

sed -e /2004/,/2005/d file

All content is deleted. I want to keep the name and year only. How can I write the script?

jschiwal 04-26-2006 03:41 AM

Do you mean that you want to delete the lines "hello world", "hello", and "goodbye" but not the lines containing
"2004" and "2005"?

This may be a bad way of doing it but here goes:
sed '/2004/,/2005/ { /200[45]/!d }' test

Inside the braces is a subrange, inside of the main range selection. If the line doesn't contain 2004 or 2005, then it is deleted.


All times are GMT -5. The time now is 12:42 AM.