find -exec using <<!EOF

find -exec using <<!EOF

am 06.11.2007 16:15:30 von 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" < -exec ed {}
1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g
w
q
!EOF \;


Cheers Peter

Re: find -exec using <<!EOF

am 06.11.2007 16:30:49 von Peter

On 6 nov, 16:15, 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" < > -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 {} < 1,$s/orabpel\.passwd\=.*$/orabpel\.passwd\=CLEAR/g
w
q
!EOF

Fails also, altough ed now opens the file...

Re: find -exec using <<!EOF

am 06.11.2007 16:37:58 von Bill Marcum

On 2007-11-06, 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" < > -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.

Re: find -exec using <<!EOF

am 06.11.2007 18:42:25 von Stephane CHAZELAS

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" < > -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

Re: find -exec using <<!EOF

am 07.11.2007 02:56:02 von unknown

Post removed (X-No-Archive: yes)

Re: find -exec using <<!EOF

am 07.11.2007 09:56:33 von Stephane CHAZELAS

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

Re: find -exec using <<!EOF

am 07.11.2007 11:20:37 von Peter

On 7 nov, 09:56, Stephane CHAZELAS wrote:
> 2007-11-07, 01:56(+00), Mario Stargard:
> [..]
>
> > find /tmp -name "*.properties" |
> > while read x ; do
>
> it should be while IFS=3D 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\=3D.*$/orabpel\.passwd\=3DCLEAR/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=E9phane

Hi St=E9phane,

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]).propert ies
|
while IFS=3D read -r x; do
ed -s \"\$0\" << !EOF
1,\$s/orabpel\.passwd=3D.*\$/orabpel.passwd=3D$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)

Re: find -exec using <<!EOF

am 07.11.2007 13:51:08 von Stephane CHAZELAS

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