find -exec using <<!EOF

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
Peter [ Di, 06 November 2007 16:15 ] [ ID #1863304 ]

Re: find -exec using <<!EOF

On 6 nov, 16:15, Peter <mail... [at] 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...
Peter [ Di, 06 November 2007 16:30 ] [ ID #1863305 ]

Re: find -exec using <<!EOF

On 2007-11-06, Peter <mailbox [at] 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.
Bill Marcum [ Di, 06 November 2007 16:37 ] [ ID #1863306 ]

Re: find -exec using <<!EOF

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
Stephane CHAZELAS [ Di, 06 November 2007 18:42 ] [ ID #1863314 ]

Re: find -exec using <<!EOF

Post removed (X-No-Archive: yes)
Notifier Deamon [ Mi, 07 November 2007 02:56 ] [ ID #1864292 ]

Re: find -exec using <<!EOF

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
Stephane CHAZELAS [ Mi, 07 November 2007 09:56 ] [ ID #1864295 ]

Re: find -exec using <<!EOF

On 7 nov, 09:56, Stephane CHAZELAS <this.addr... [at] is.invalid> 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)
Peter [ Mi, 07 November 2007 11:20 ] [ ID #1864299 ]

Re: find -exec using <<!EOF

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
Stephane CHAZELAS [ Mi, 07 November 2007 13:51 ] [ ID #1864307 ]
Linux » comp.unix.shell » find -exec using <<!EOF

Vorheriges Thema: I am not able to parse the following
Nächstes Thema: Re: LaTeX tutorial updated