LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   help removing some text from a file (sed) (https://www.linuxquestions.org/questions/programming-9/help-removing-some-text-from-a-file-sed-473579/)

BrianK 08-13-2006 06:42 PM

help removing some text from a file (sed)
 
I have a text file that looks something like this:

---------------------------
begin
foo [good 89 98 89 8 78 76 56 56 8 ] "N" [bad 987 78 69 9 6 889 89 0 90 890 9 ] "other" [good 09890 7890 89 89 89 90 90 ]
jkak
asj
---------------------------

I want to remove the stuff in bold.

I've tried sed '/"N"/,/]/d', but it doesn't seem to work....

> sed '/"N"/,/]/d' tester
begin

I also tried this:

> sed 's/"N".*]//g' tester
begin
foo [good 89 98 89 8 78 76 56 56 8 ]
jkak
asj

... but that doesn't stop at the first ']'.

ideas?

jlliagre 08-13-2006 07:03 PM

Try that one:
Code:

sed 's/"N" [^]]*]//'

BrianK 08-13-2006 07:10 PM

Quote:

Originally Posted by jlliagre
Try that one:
Code:

sed 's/"N" [^]]*]//'

that makes sense... couldn't think how to get the first ']' after the '"N"'.. of course it makes perfect sense once it's been spelled out.

Thanks!

... err... edit... if we modify the file a bit, this method stops working. i.e.:

----------------
begin
foo [good 89 98 89 8 78 76 56 56 8 ] "N" [bad 987 78 69 9 6
889 89 0 90 890 9 ]
"other" [good 09890 7890 89 89 89 90 90 ]
jkak
asj
-----------------

it should work in either case.


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