LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 12-14-2007, 09:00 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
sed: need to replace text that lies within square backets. how?


I have a string that looks like so:

/path/to/foo.[001-500].bar

I want to make that string look like this:

/path/to/foo.*.bar

I can't seem to figure out how to escape the square brackets. I can do one or the other, but not both, and not the stuff inside them.

ideas?
 
Old 12-14-2007, 09:13 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
"s/\[.*\]/\*/" should work.

Or,a bit more readable - "s:\[.*\]:\*:"
 
Old 12-14-2007, 09:20 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
awk
Code:
# echo "/path/to/foo.[001-500].bar" | awk -F"." '{print $1".*."$3}'
/path/to/foo.*.bar
# echo "/path/to/foo.[001-500].bar" | awk 'gsub(/\[.*\]/,"*")'
/path/to/foo.*.bar
 
  


Reply



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
using sed to replace text on one line in a text file vo1pwf Linux - Newbie 5 06-24-2009 07:54 AM
Sed - replace text only in a certain range twantrd Programming 4 11-30-2006 06:54 PM
SED - replace text in file on specific line 3saul Linux - Software 1 03-04-2006 07:01 PM
Using sed to replace a lot of text Wynd Programming 9 10-07-2005 03:47 AM
can I replace text with the result of "wc" using sed? BrianK Linux - General 1 04-21-2004 01:15 PM

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

All times are GMT -5. The time now is 05:52 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