|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I can't get figured it out... yet
The script below should edit al ".properties" files and replace a string. Running the ed commands on a single file works without a flaw.... Can somebody give me a hint ?? #!/bin/ksh -x find /tmp -name "*.properties" <<!EOF -exec ed {} 1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g w q !EOF \; Cheers Peter |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 6 nov, 16:15, Peter <mail...@petervannes.nl> wrote:
> I can't get figured it out... yet > The script below should edit al ".properties" files and replace a > string. > Running the ed commands on a single file works without a flaw.... > > Can somebody give me a hint ?? > > #!/bin/ksh -x > > find /tmp -name "*.properties" <<!EOF > -exec ed {} > 1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g > w > q > !EOF \; > > Cheers Peter Tried this #!/bin/ksh find /tmp -name "*.properties" -exec ed {} <<!EOF \; 1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g w q !EOF Fails also, altough ed now opens the file... |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 2007-11-06, Peter <mailbox@petervannes.nl> wrote:
> I can't get figured it out... yet > The script below should edit al ".properties" files and replace a > string. > Running the ed commands on a single file works without a flaw.... > > Can somebody give me a hint ?? > > > #!/bin/ksh -x > > find /tmp -name "*.properties" <<!EOF > -exec ed {} > 1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g > w > q > !EOF \; > > > Cheers Peter > I would recommend putting the ed commands in a separate script. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
2007-11-06, 07:15(-08), Peter:
> I can't get figured it out... yet > The script below should edit al ".properties" files and replace a > string. > Running the ed commands on a single file works without a flaw.... > > Can somebody give me a hint ?? > > > #!/bin/ksh -x > > find /tmp -name "*.properties" <<!EOF > -exec ed {} > 1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g > w > q > !EOF \; [...] find /tmp -name "*.properties" -exec sh -c ' ed "$1" << \EOF 1,$s/orabpel\.passwd=.*$/orabpel.passwd=CLEAR/g w q EOF ' {} {} \; -- Stéphane |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Tue, 06 Nov 2007 07:15:30 -0800, Peter wrote:
> I can't get figured it out... yet > The script below should edit al ".properties" files and replace a > string. > Running the ed commands on a single file works without a flaw.... > > Can somebody give me a hint ?? > > > #!/bin/ksh -x > > find /tmp -name "*.properties" <<!EOF -exec ed {} > 1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g w > q > !EOF \; > > > Cheers Peter When I do this sort of thing, I use "while" and "read", like so: find /tmp -name "*.properties" | while read x ; do ed -s "$x"<<-_HERE_ 1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g w q _HERE_ done This construct works well in ksh, but in bash, any variables you might set after the pipe are lost when the while loop finishes. I suppose that's more proper, but it's convenient none-the-less. Cheers, Mario |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
2007-11-07, 01:56(+00), Mario Stargard:
[..] > find /tmp -name "*.properties" | > while read x ; do it should be while IFS= read -r x; do and it doesn't work if the file names contain newline characters. > ed -s "$x"<<-_HERE_ You need to escape _HERE_, otherwise, the $s below will be expanded by the shell. > 1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g > w > q > _HERE_ > done > > This construct works well in ksh, but in bash, any variables you might > set after the pipe are lost when the while loop finishes. I suppose > that's more proper, but it's convenient none-the-less. [...] It's also the case in many implementations of ksh like those derived from the public domain version of it (pdksh, mksh, posh). -- Stéphane |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On 7 nov, 09:56, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2007-11-07, 01:56(+00), Mario Stargard: > [..] > > > find /tmp -name "*.properties" | > > while read x ; do > > it should be while IFS= read -r x; do > > and it doesn't work if the file names contain newline > characters. > > > ed -s "$x"<<-_HERE_ > > You need to escape _HERE_, otherwise, the $s below will be > expanded by the shell. > > > 1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g > > w > > q > > _HERE_ > > done > > > This construct works well in ksh, but in bash, any variables you might > > set after the pipe are lost when the while loop finishes. I suppose > > that's more proper, but it's convenient none-the-less. > > [...] > > It's also the case in many implementations of ksh like those > derived from the public domain version of it (pdksh, mksh, > posh). > > -- > Stéphane Hi Stéphane, Because find could not return the set of files i needed (need to use expressions) is switched over mario's solution. This is what i have now; ls -1r ${CRMIDSTREL}/CRMI_HOME/Properties/crmi-+([a-z,0-9]).properties | while IFS= read -r x; do ed -s \"\$0\" << !EOF 1,\$s/orabpel\.passwd=.*\$/orabpel.passwd=$bpelpwd/g w q EOF done print "Done" This fails with error "./PrepRelease.ksh[165]: 0403-057 Syntax error at line 167 : `<' is not matched." (line 167 is ed -s \"\$0\" << !EOF) Probably is stumble upon what you mentioned before, escaping _HERE_ . Can not figure out what's wroing with this .. thanks (again) |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
2007-11-07, 02:20(-08), Peter:
[...] > while IFS= read -r x; do > ed -s \"\$0\" << !EOF > 1,\$s/orabpel\.passwd=.*\$/orabpel.passwd=$bpelpwd/g > w > q > EOF > done > > print "Done" > > This fails with error "./PrepRelease.ksh[165]: 0403-057 Syntax error > at line 167 : `<' is not matched." > (line 167 is ed -s \"\$0\" << !EOF) > Probably is stumble upon what you mentioned before, escaping _HERE_ . > Can not figure out what's wroing with this .. [...] cat << EOF $var EOF outputs the content of the var variable. cat << 'EOF' $var EOF outputs "$var". ! is not a special character, so cat << !EOF $var !EOF is the same as cat << whatever $var whatever and cat << !EOF $var EOF the same as cat << onething $var another that is, an error. -- Stéphane |
|
![]() |
| Outils de la discussion | |
|
|