ISO one-line patching command
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > ISO one-line patching command




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    ISO one-line patching command  
kj


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-25-04 03:34 PM



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?

Thanks!

kj
--
NOTE: In my address everything before the period is backwards.





[ Post a follow-up to this message ]



    Re: ISO one-line patching command  
Bob Paulsen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Re: ISO one-line patching command  
Charles Demas


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-25-04 05:34 PM

In article <c6gicr$r6e$1@reader2.panix.com>, kj  <socyl@987jk.com> 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 and mv like this (untested)?

sed '/use Test::More tests => 11;/s/11/9/' infile > outfile
mv outfile infile


Chuck Demas

--
Eat Healthy        |   _ _   | Nothing would be done at all,
Stay Fit           |   @ @   | If a man waited to do it so well,
Die Anyway         |    v    | That no one could find fault with it.
demas@theworld.com |  \___/  | http://world.std.com/~cpd





[ Post a follow-up to this message ]



    Re: ISO one-line patching command  
Juha Laiho


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-25-04 07:34 PM

kj <socyl@987jk.com> said:
>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;

How about using "diff -e" to create the appropriate 'ed' commands to
make this change, and upon installation run the generated commands
through 'ed'.

Not much different from 'patch', but doesn't require the patch program
to be available, and has a way to programmatically generate the
differences.
--
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)





[ Post a follow-up to this message ]



    Re: ISO one-line patching command  
kj


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-26-04 07:34 PM


Many thanks for the replies.

In <c6guuc$5p4$3@ichaos.ichaos-int> Juha Laiho <Juha.Laiho@iki.fi> writes:

>kj <socyl@987jk.com> said: 
[vbcol=seagreen]
>How about using "diff -e" to create the appropriate 'ed' commands to
>make this change, and upon installation run the generated commands
>through 'ed'.

That's an intriguing idea.  The output of "diff -e" is simply:

12c
use Test::More tests => 9;
.

Would I have to put these commands in a separate file for ed to
run them, or could I feed them to ed directly?

Thanks!

kj

--
NOTE: In my address everything before the period is backwards.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:15 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register