LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-25-2008, 02:35 AM   #1
lothario
Member
 
Registered: Apr 2004
Posts: 340

Rep: Reputation: 30
replace a text pattern with the reverse of another text pattern


To replace all the occurrences of OLD_text_PATTERN with NEW_TEXT_PATTERN in a specific file, I do:
Code:
replace -s   'OLD_text_PATTERN'   'NEW_TEXT_PATTERN'   --   /tmp/the_specific_file
Now, I also need replace all the occurrences of 2nd_text_PATTERN with reverse(NEW_TEXT_PATTERN) in the same file.
In other words, replace all the occurrences of 2nd_text_PATTERN with NRETTAP_TXET_WEN

How can I do this?
 
Old 07-25-2008, 02:49 AM   #2
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 211

Rep: Reputation: 32
Quote:
Originally Posted by lothario View Post
replace all the occurrences of 2nd_text_PATTERN with NRETTAP_TXET_WEN
How can I do this?
does the following help ful to you??

Quote:
sed 's/pattern_one/new_pattern_one/;s/pattern_two/new_pattern_two/' inputfile > outputfile
 
Old 07-25-2008, 03:21 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,508

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Code:
man rev
is what you need.
 
Old 07-25-2008, 07:14 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by colucix View Post
Code:
man rev
is what you need.
Wow, the world's shortest man page....

rev seems to reverse the order of whole lines.

lothario;
I assume that you need some kind of general solution in which you replace some text with the reverse of another pattern. (Otherwise, you would just enter the specific pattern you want.)

Somewhere there must be a command for reversing a word, but I can't find it....

Please tell us more about what you are trying to accomplish. There might be some other solution.
 
Old 07-25-2008, 07:39 AM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,508

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by pixellany View Post
Wow, the world's shortest man page....
Yeah, it is one of the shortest I have ever seen!

Quote:
Originally Posted by pixellany View Post
Somewhere there must be a command for reversing a word, but I can't find it....
The rev command do this as well:
Code:
$ echo NEW_TEXT_PATTERN | rev
NRETTAP_TXET_WEN
See man rev for details...
 
Old 07-25-2008, 02:43 PM   #6
lothario
Member
 
Registered: Apr 2004
Posts: 340

Original Poster
Rep: Reputation: 30
Thanks for all the tips.
I got it working yesterday and was busy using it.
Here it is ...

Code:
replace -s   'OLD_text_PATTERN'     `echo $any_TEXT_to_be_reversed | rev`   --   /tmp/target_File.txt
 
  


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
How to replace string pattern with multi-line text in bash script? brumela Linux - Newbie 6 04-21-2011 06:56 AM
renaming text files based upon a pattern in their content Spacepup Linux - General 1 07-28-2005 01:43 PM
Removing Text in a single line starting with one pattern ending on another mgwheeler Programming 13 08-03-2004 04:36 PM
Need text pattern compare script kscott121 Linux - Software 4 05-10-2004 01:13 PM
Find string pattern in directory of text files magnum818 Linux - Newbie 2 10-15-2003 08:19 PM


All times are GMT -5. The time now is 06:57 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration