Sed to make global replacements.

Randal Schwartz merlyn at iwarp.intel.com
Sun Dec 3 04:37:58 AEST 1989


In article <37090 at ames.arc.nasa.gov>, gahooten at orion (Gregory A. Hooten) writes:
| I am working with sed on a file, and need to make a global replacement, but 
| what I am replacing are special characters to sed.  I do not know how to 
| replace them.  
| 
| I would like to change the characters \(12 to 1/2, but every thing I try
| thinks the \( is the start of a character group.  I would like any help 
| possible on this problem.  

In sed, you need to escape the backslash, as in:

% sed 's,\\(12,1/2,g' <old >new

Now, with Perl (of course, you knew it was coming :-), if you had a
whole directory full of these files, you could perform this
substitution, saving the original files as filename.bak, with:

% perl -p -i.bak -e 's,\\(12,1/2,g;' *

Cool, eh?  No fuss, no muss, and all in one process.

Just another Perl hacker, waiting for comp.lang.perl...
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III  |
| merlyn at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/



More information about the Comp.unix.questions mailing list