04-25-04 04:33 PM
On Sun, 25 Apr 2004 14:36:11 +0000, kj wrote:
>
>
> I am writing a bash script that performs an elaborate software
> installation. One step in this installation involves changing a single
> line in a text file in the distributed source code, from
>
> use Test::More tests => 11;
>
> to
>
> use Test::More tests => 9;
>
> I could have my installation script generate a patch file and apply it,
> but it seems to me that there ought to be simpler ways for my script to
> carry out this simple patching operation.
>
> One possibility would be:
>
> PERL -i -pe 's/^(use Test::More tests => ) 11;$/$1 9/' file_to_patch
>
> ...but this requires perl, which may not be available in all environments.
>
> Any better (simpler and/or more portable) alternatives?
>
How about using sed:
$ mv file file-orig
$ sed '/use Test::More tests => 11;/s/11/9/' < file-orig > file
Here is a bash-only solution (but I'm not sure if it is truly robust
on a variety of file formats):
============ fixit.sh =================================
#!/bin/bash
IFS=
while read line ; do
[ "$line" == "use Test::More tests => 11;" ] &&
echo "use Test::More tests => 9;" ||
echo "$line"
done;
========================================
================
Use it like this:
$ mv file file-orig
$ ./fixit.sh < file-orig > file
[ Post a follow-up to this message ]
|