string replacement
 
*
Welcome, Guest. Please login or register. January 09, 2009, 11:03:11 PM


Login with username, password and session length


Pages: [1]   Go Down
  Print  
Author Topic: string replacement  (Read 1096 times)
0 Members and 1 Guest are viewing this topic.
wwells
Full Member
***
Posts: 18


« Reply #2 on: May 27, 2007, 05:16:57 PM »

As usual, there are at least 3 different ways to accomplish the task. I would use sed for a one time task. I would probably create a perl program to do it if this was a task that I performed a lot.
Logged
Michael
Administrator
Hero Member
*****
Posts: 539


« Reply #1 on: May 27, 2007, 03:22:44 PM »

I would probably use a combination. Havent had to do anything like this for a long long time.

I would use sed/perl/awk when generating a file.

When modifying an existing file, depending on the complexity of the string comparision look into using ed/vi/perl/awk.

As I do very little work with programs requiring text recognition I would probably use ed or vi and put his in a small script using redirected input

The 'exciting part' part would include <<EOF
g/XXX/s//ZZZ/g
w!
q
EOF

Now, as I am not a regular shell script writer I am expecting someone to improve on this.
Logged
GhostDJ
Jr. Member
**
Posts: 5


« on: May 22, 2007, 09:43:05 AM »

 Grin hello there !

I just want to know your own way (better ?) to do this :

replace without doing it manually (vi, sed) the string TOTO by TITI in XXX file

my way :
find . -name "XXX" | xargs -t perl -pi.save -e 's/TOTO/TITI/'

or (but with 2 lignes) :
cat XXX | sed 's/TOTO/TITI/g' > XXX.new
cat XXX.new >XXX
in this way i think we keep the permissions...?


thanks !
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 5.501 seconds with 18 queries.




eXTReMe Tracker

Terms of Use and Privacy and Security Policies
Copyright 2001-2008 Michael Felt and ROOTVG.NET