LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-13-2006, 06:42 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
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?
 
Old 08-13-2006, 07:03 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Try that one:
Code:
sed 's/"N" [^]]*]//'
 
Old 08-13-2006, 07:10 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
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.

Last edited by BrianK; 08-13-2006 at 07:13 PM.
 
  


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
removing text shadows in kde; removing taskbar color gradient webazoid Linux - Software 1 04-11-2006 02:56 AM
SED - replace text in file on specific line 3saul Linux - Software 1 03-04-2006 07:01 PM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 04:32 PM
Help with a script to edit text file (awk? sed?) rickh Linux - Newbie 8 04-21-2005 08:24 PM
Removing <CR> using sed stv_t Programming 2 10-04-2003 04:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:13 AM.

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
Open Source Consulting | Domain Registration