[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Scripting again...



On Tue, Jan 17, 2006 at 07:40:48AM +0100, John Smith wrote:
> Hi All,
> 
> 	how do you change (from the command line) with (sed/awk/... 
> anything that's available in the installation environment)
> 
>         "text:\n someothertext" to "text: someothertext"
> 
> 	The trick is in the newline of course.
> 
> 	I now do with
> 
> 	cat output.txt | tr '\n' '!' | sed -e 's/text:! someothertext/text: someothertext/g' | tr '!' '\n'
> 
> 	But I bet somebody can do better...

Personally, I'd use perl for this kind of thing:

$ perl -p0e 's/text:\n someothertext/text: someothertext/g' infile >outfile

or

$ perl -i -p0e 's/text:\n someothertext/text: someothertext/g' file

to edit in place.

The option -0 makes perl use \0 as the input record delimiter, which is
typically okay for text files.  If you really must match \0 within the
regex (e.g. to mess with binary files) you can use

$ perl -p0777e 's/foo\0bar/baz/g' infile >outfile

to have perl slurp in the whole file as one piece...

(See "perl -h" and "perldoc perlrun" for details.)

Cheers,
Almut



Reply to: