PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > find -exec using <<!EOF
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

find -exec using <<!EOF

Réponse
 
LinkBack Outils de la discussion
Vieux 06/11/2007, 15h15   #1
Peter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
Vieux 06/11/2007, 15h30   #2
Peter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec using <<!EOF

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

  Réponse avec citation
Vieux 06/11/2007, 15h37   #3
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec using <<!EOF

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.
  Réponse avec citation
Vieux 06/11/2007, 17h42   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 07/11/2007, 01h56   #5
Mario Stargard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec using <<!EOF

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
  Réponse avec citation
Vieux 07/11/2007, 08h56   #6
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 07/11/2007, 10h20   #7
Peter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: find -exec using <<!EOF

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)

  Réponse avec citation
Vieux 07/11/2007, 12h51   #8
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h34.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16461 seconds with 16 queries