LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 03-26-2012, 06:57 AM   #1
mavadikarmayur
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Rep: Reputation: Disabled
Replace a string @CURRANGE("***","***") to @CURRANGE("xxx","xxx") in a file


Hi all,

I have a file in which I need to find and replace a string @CURRANGE("***","???") to @CURRANGE("---","^^^") where ***, ???, --- and ^^^ can be any string. I feel I need to use sed to do it but if someone could be more specific that would be much more helpful.

Thank You.
Mayur.
 
Old 03-26-2012, 07:25 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hi Mayur and welcome to LinuxQuestions!

Here is an example:
Code:
sed 's/@CURRANGE("[^"]*","[^"]*")/@CURRANGE("new_string_one","new_string_two")/g' file
where the expression [^"]* means zero or any number of characters different than ". This ensures that two or more expressions in the same line (if any) are changed accordingly. Example:
Code:
$ cat file
text @CURRANGE("any string","yet another string") text @CURRANGE("whatever","235472934629746") text
$
$ sed 's/@CURRANGE("[^"]*","[^"]*")/@CURRANGE("new_string_one","new_string_two")/g' file
text @CURRANGE("new_string_one","new_string_two") text @CURRANGE("new_string_one","new_string_two") text
Use the -i option of sed if you want to edit the file in place. Use -i.bck to keep a backup copy of the original file, that will be named by adding the (custom) suffix .bck. Hope this helps.
 
Old 03-26-2012, 08:10 AM   #3
mavadikarmayur
LQ Newbie
 
Registered: Mar 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thumbs up

Hi colucix,

Brilliant !!

Worked very Smooth !!

Thanks so much !!!!!
 
Old 03-26-2012, 08:32 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You're welcome!
 
  


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
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
unpredictable "delete" "move to trash" or "cut" file menu option dorianrenato Linux - General 3 11-28-2011 06:41 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
"ping xxx.abc.local" ok but "ping xxx" fail powah Linux - Networking 2 10-13-2006 08:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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