LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Search word and delete only the word and the line using Sed command (https://www.linuxquestions.org/questions/linux-newbie-8/search-word-and-delete-only-the-word-and-the-line-using-sed-command-888704/)

kbmukesh 06-28-2011 02:39 AM

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.

acid_kewpie 06-28-2011 03:19 AM

This doesn't look like homework, so if it is, well done for obscuring it ;)

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

druuna 06-28-2011 03:34 AM

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.

acid_kewpie 06-28-2011 03:51 AM

Odd, fine for me. Maybe some whitespace issues aside.

kbmukesh 06-28-2011 06:35 AM

Thanks to both of you.

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


All times are GMT -5. The time now is 10:34 PM.