Text find and replace

I wanted to compile the latest Homebank personal accounting package. The source package has SVG icons, but the PET package in Puppy4 has much smaller PNG icons. I did this by using Turma to do a global replacement of all occurrences of '.svg' in the sources files with '.png', and I converted all the SVG images to 16x16 PNG images. This resulted in a considerably smaller package.

However, Turma is a GTK 1.2 application and is not by default in Puppy4. So when I wanted to compile the latest Homebank, I thought that we need something in Puppy by default that can do this. Pfind only finds -- and it found that 16 files have '.svg' in them.

So, I decided to put the 'rpl' utility into Woof. This is a commandline text find and replace. Unlike sed, it replaces text directly in the file. It also handles recursive searches (into subdirectories). To make the replacement in Homebank was easy:

# cd src
# rpl -p '.svg' '.png' *.c

The '-p' causes the utility to ask for confirmation for each file it finds that needs replacement. In all, there were 68 matches.

So, 'rpl', with it's help file, will be in Woof-Puppy alpha3. What would be nice would be a GUI for it... ...I haven't got time for that though.

Home page: http://www.laffeycomputer.com/rpl.html

Note, there is another utility called 'replace' that does the same thing, and may be slightly more sophisticated:
http://replace.richardlloyd.org.uk/


Posted on 19 Mar 2009, 22:05


Comments:

Posted on 19 Mar 2009, 22:32 by Pizzasgood
Sed
Actually, Sed accepts a -i parameter that stands for "in-place", and when used it will indeed edit files in-place.

(rpl still sounds like the better option though)


Posted on 19 Mar 2009, 22:59 by BarryK
re: sed
I never knew sed could do that! Thanks for letting me know.

What about recursively descending through subdirectories to search files? ...and more than one file? So, I guess rpl is better as a batch processor?

sed man page:
http://linux.die.net/man/1/sed



Posted on 19 Mar 2009, 23:51 by dogone
Replace superior?
From what I'm reading, The Richard Lloyd's replace utility is superior to rpl in several respects. Lloyd also implies that rpl is not GPL code. Cast my vote for inclusion of "replace" in Woof.


Posted on 19 Mar 2009, 24:42 by Sage
User perspective
Is there a plain text file, preferably accessed via a GUI menu item, that lists such powerful commands, as well as pointing to their help file?
It's mythology that folks tremble at the console (apart from kiddies) because most will have used DOS daily in days of yore. But it's necessary to point to all these options from the normal UI with a one-liner at that locationexplaining that some utilities can only be used by direct command. Providing the accompanying help file lists the switches - no problem. After all, I've always spelled 'confirmation' with a 'p' !


Posted on 20 Mar 2009, 3:06 by big_bass
rpl
I'll have to try rpl thanks for including it

sed makes me dizzzzy :D

so ,I use "replace" when I can because it's easy

an example here
cat /some_file.txt | 'old_string' 'new_string'

can't get easier than that

big_bass


Posted on 20 Mar 2009, 3:13 by big_bass
rpl

an example here
cat /some_file.txt |replace 'old_string' 'new_string'

can't get easier than that

ouch! did a typo above


Posted on 20 Mar 2009, 9:57 by Pizzasgood
Sed
What about recursively descending through subdirectories to search files? ...and more than one file? So, I guess rpl is better as a batch processor?
The simple way is like this, but it won't work with paths that have spaces:
sed -i 's/\.svg/.png/g' $(find /some/path -type f)

To cover spaces, you need something more like this:
find /some/path -type f -exec sed -i 's/\.svg/.png/g' "{}" \;

That still doesn't let you confirm, but you could probably squeeze some sort of prompt into there. Otherwise, you could split it into two parts, with the prompt and sed call as either another script or a function, and then use that script/function as the parameter for the find command.


Posted on 20 Mar 2009, 15:59 by BarryK
replaceit
Puppy4 has 'replaceit', which is another, even simpler, replace utility. Can't do in-place file replacements though.



Posted on 20 Mar 2009, 16:01 by BarryK
rpl licence
Hmm, yes. May have to reconsider, put in 'replace' instead.


Posted on 20 Mar 2009, 19:08 by Bm
HomeBank
About Homebank.
In order for OFX records to be imported. ofxlib is to be compiled with Homebank, I think. I tried compiling separately and alltho I had a ofxlib, the import didn't work.

Can you consider this?


Posted on 22 Mar 2009, 9:46 by dogone
"Replace" and wildcards
Forgive if this should be a forum post somewhere(?), but I find no reference wildcards in Replace documentation. I need to remove one entire line in each of several hundred ASCII files. The line in each file begins identically and ends uniqely. I need the equivalent of Replace "From the beginning to the * \n" *.files


Posted on 11 May 2009, 9:19 by Joe J
RPL
The RPL program in the Ubuntu repository is a free version licensed under the GPL.