LinuxQuestions.org
Help answer threads with 0 replies.
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 06-28-2011, 02:39 AM   #1
kbmukesh
LQ Newbie
 
Registered: Jun 2008
Posts: 6

Rep: Reputation: 0
Search word and delete only the word and the line using Sed command


Hi All,
Struck with this, please help. Want to search for ~ and delete it as well as to append the entire line to the above line.
For Ex:
1111 xxxx date Sandy area is
~around this area.
3222 xxx date There seems to
~left side of map, the colours are accurate (showing green areas) Even if I
~zoom in, the green parks,
xxx 3258 date The dammed up
~away, the "other" body of water varies
~black Natural gas leaching.

IT MUST LOOK LIKE:
1111 xxxx date Sandy area is around this area.
3222 xxx date There seems to left side of map, the colours are accurate (showing green areas) Even if I zoom in, the green parks,
xxx 3258 date The dammed up away, the "other" body of water varies black Natural gas leaching.
 
Old 06-28-2011, 03:19 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
This doesn't look like homework, so if it is, well done for obscuring it

sed ':a;N;$!ba;s/\n/ /g' file.txt

Last edited by acid_kewpie; 06-28-2011 at 03:21 AM.
 
Old 06-28-2011, 03:34 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

acid_kewpie's example doesn't work on my side, this does:
Code:
sed '/^~/!{:tag;N;s/\n~//;b tag}' infile
Hope this helps.
 
Old 06-28-2011, 03:51 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
Odd, fine for me. Maybe some whitespace issues aside.
 
Old 06-28-2011, 06:35 AM   #5
kbmukesh
LQ Newbie
 
Registered: Jun 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks to both of you.

"acid_kewpie" code doesn't work for me also and, "druuna" does.
 
  


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 append word at end of line if word is missing franjo124 Linux - Newbie 3 03-08-2012 08:41 PM
[SOLVED] Delete range word to word with sed when all you have is one line subby80 Linux - Enterprise 16 09-02-2010 05:04 AM
[SOLVED] SED - substitute a word only in a certain line carolflb Linux - Newbie 3 02-02-2010 09:30 AM
search word and comment or delete asim.mcp Programming 8 08-15-2009 02:20 AM
sed to delete a line for a word and line above cmontr Programming 11 07-03-2008 08:33 AM


All times are GMT -5. The time now is 06:02 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration