LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 04-26-2006, 03:23 AM   #1
Hydrap
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:

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

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


Reply


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 07:31 AM
Sed problem Miro1 Programming 3 04-09-2005 09:02 AM
sed problem Warmduvet Programming 2 09-15-2004 06:33 PM
Help Sed Problem anirudh Linux User Groups (LUG) 1 08-30-2004 02:25 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM


All times are GMT -5. The time now is 04:38 PM.

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