Zain
Zain

Reputation: 53

Problem with matching a specific extension only using find command in shell script

I want to make some changes on a list of XML files in a directory using shell script and some perl commands. Here it is an example of perl commands:

find "." -name "*.xml" | xargs perl -pi -e 's/\s+/ /g' *

All Perl commands work fine, but the problem is, the shell script executes the commands even on itself, in other words, when I run the shell script the perl commands changes the shell scripts with all other XML files!!! NOTE: XML files and Shell script are located on the same directory, and should not this part of the command:

 find "." -name "*.xml" 

match only the files with XML extension !!!

any suggestions please?!

Upvotes: 0

Views: 43

Answers (2)

Rafael
Rafael

Reputation: 7746

As pointed out by Red Cricket, you have a * at the end of your command, get rid of that.

Also, I recommend using -exec and sed:

find -name '*.xml' -exec sed 's/\s\+/ /g' {} \;

Upvotes: 0

Red Cricket
Red Cricket

Reputation: 10470

Your have a wild card, *, and the end of your command!

Upvotes: 1

Related Questions