Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl one liner

Status
Not open for further replies.

johnfm00

Technical User
Dec 1, 2003
12
0
0
AU
hi, can anyone tell me why the following line only
creates the .profile.bak, but does not make the changes inside the files ?



find . /backup/johnm -name ".profile" -exec perl -pi.bak -e 's(COBDIR=/opt/lib/cobv4.1.40/cobol/)(COBDIR=/opt/lib/cobv4.2.0/cobol)g' {} \;

 
I don't have access to a Unix box currently, but the
syntax of your find command looks odd to me. You've
got a . meaning current directory, then a space, then
another directory path. Is it all supposed to be one
path, i.e., "./backup/johnm", meaning "backup/johnm" is
a directory under the current one? (Maybe I'm wrong here.)

I don't see why you're bothering with find at all. If
the directory structure is as I speculated above, you
could just do

Code:
perl -pi.bak -e 's(COBDIR=/opt/lib/cobv4.1.40/cobol/)(COBDIR=/opt/lib/cobv4.2.0/cobol)g' ./backup/johnm/*.profile

Your shell will expand ./backup/johnm/*.profile to the list
of all files in ./backup/johnm with the .profile extension.

If it's really 2 directories, you could do

Code:
perl -pi.bak -e 's(COBDIR=/opt/lib/cobv4.1.40/cobol/)(COBDIR=/opt/lib/cobv4.2.0/cobol)g' ./*.profile /backup/johnm/*.profile

or just run it twice, once with the file argument ./*.profile and once with /backup/johnm/*.profile

 
thanks mike. I should have looked closer and I would have noticed I had an extra / at the end of (COBDIR=/opt/lib/cobv4.1.40/cobol/) that wasn't required.
 
Glad you found the cause of the problem.

I've looked up find syntax since I last posted and it is
okay with multiple pathnames, assuming that's really what
you intended. I don't think I've ever used it that way.

Still don't see why you'd bother with find, though, as
Perl will do the job without it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top