From: Michael Laajanen on
Hi,

I should not ask "can" always here more "how"

I have a number of files that I like to look for the line

`define SIM 0 and change it to `define SIM 1

How can I do that from a script?


/michael
From: Chris Ridd on
On 2010-07-15 17:05:51 +0100, Michael Laajanen said:

> Hi,
>
> I should not ask "can" always here more "how"
>
> I have a number of files that I like to look for the line
>
> `define SIM 0 and change it to `define SIM 1
>
> How can I do that from a script?

Use sed? Personally I prefer using perl with its convenient in-place
editing flag (-i):

perl -pi -e 's/define SIM 0/define SIM 1/g' *

--
Chris

From: Michael Laajanen on
Hi,

Chris Ridd wrote:
> On 2010-07-15 17:05:51 +0100, Michael Laajanen said:
>
>> Hi,
>>
>> I should not ask "can" always here more "how"
>>
>> I have a number of files that I like to look for the line
>>
>> `define SIM 0 and change it to `define SIM 1
>>
>> How can I do that from a script?
>
> Use sed? Personally I prefer using perl with its convenient in-place
> editing flag (-i):
>
> perl -pi -e 's/define SIM 0/define SIM 1/g' *
>
Excellent :) whenever I use sed I always pipe to a new file and then
copy it back to the original name this is much better. Can this be done
with sed aswell?

/michael
From: Lew Pitcher on
On July 15, 2010 13:54, in comp.unix.solaris, michael_laajanen(a)yahoo.com
wrote:

> Hi,
>
> Chris Ridd wrote:
>> On 2010-07-15 17:05:51 +0100, Michael Laajanen said:
>>
>>> Hi,
>>>
>>> I should not ask "can" always here more "how"
>>>
>>> I have a number of files that I like to look for the line
>>>
>>> `define SIM 0 and change it to `define SIM 1
>>>
>>> How can I do that from a script?
>>
>> Use sed? Personally I prefer using perl with its convenient in-place
>> editing flag (-i):
>>
>> perl -pi -e 's/define SIM 0/define SIM 1/g' *
>>
> Excellent :) whenever I use sed I always pipe to a new file and then
> copy it back to the original name this is much better. Can this be done
> with sed aswell?

GNU sed offers the -i and --in-place options, which cause sed to apply the
edit changes directly to the file.

However, it appears that these options are GNU extensions, and not part of
the POSIX/SUS sed.

--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------


From: Michael Laajanen on
Hi,

Lew Pitcher wrote:
> On July 15, 2010 13:54, in comp.unix.solaris, michael_laajanen(a)yahoo.com
> wrote:
>
>> Hi,
>>
>> Chris Ridd wrote:
>>> On 2010-07-15 17:05:51 +0100, Michael Laajanen said:
>>>
>>>> Hi,
>>>>
>>>> I should not ask "can" always here more "how"
>>>>
>>>> I have a number of files that I like to look for the line
>>>>
>>>> `define SIM 0 and change it to `define SIM 1
>>>>
>>>> How can I do that from a script?
>>> Use sed? Personally I prefer using perl with its convenient in-place
>>> editing flag (-i):
>>>
>>> perl -pi -e 's/define SIM 0/define SIM 1/g' *
>>>
>> Excellent :) whenever I use sed I always pipe to a new file and then
>> copy it back to the original name this is much better. Can this be done
>> with sed aswell?
>
> GNU sed offers the -i and --in-place options, which cause sed to apply the
> edit changes directly to the file.
>
> However, it appears that these options are GNU extensions, and not part of
> the POSIX/SUS sed.
>
Okey, I stick to perl.

BTW, who said this NG was dead, it took only a couple of minutes... :)

/michael