Go Job Hunting at the LQ Job Marketplace
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-26-2006, 04:23 AM   #1
LQ Newbie
Registered: Aug 2005
Posts: 6

Rep: Reputation: 0
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:

hello world


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?
Old 04-26-2006, 04:41 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 658Reputation: 658Reputation: 658Reputation: 658Reputation: 658Reputation: 658
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
sed problem Hydrap Linux - General 3 03-30-2006 08:31 AM
Sed problem Miro1 Programming 3 04-09-2005 10:02 AM
sed problem Warmduvet Programming 2 09-15-2004 07:33 PM
Help Sed Problem anirudh Linux User Groups (LUG) 1 08-30-2004 03:25 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM

All times are GMT -5. The time now is 05:45 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration