Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Directory Recursion from the Command Line?

by dvergin (Monsignor)
on Apr 15, 2003 at 04:32 UTC ( #250472=perlquestion: print w/replies, xml ) Need Help??
dvergin has asked for the wisdom of the Perl Monks concerning the following question:

I don't use one-liners routinely, but when the boss-man asked for a quicky to make the same change in 150 files in a directory, I dashed off:
perl -pi -e 's/this/that/' *
...and looked like a hero.

Then he said, "Make it work for a whole directory branch." I was stumped. I can (and did) write a short script to do this. But I have a lingering suspicion that there is some command-line magic that can, in effect do:

perl -r -pi -e 's/this/that/' *
Where the '-r' switch works as in other Linux commands to cause the requested operation to be performed on all directories including and under the current one.

Sadly, there is no '-r' switch for the Perl executable.

Does anyone have a quick command-line hack (rather than a script) to accomplish the requested task.

"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall

Replies are listed 'Best First'.
Re: Directory Recursion from the Command Line?
by Anonymous Monk on Apr 15, 2003 at 05:00 UTC

      I had just posted and gone to read other current items and there it was in the thread you have pointed to.

Re: Directory Recursion from the Command Line?
by crouchingpenguin (Priest) on Apr 15, 2003 at 13:08 UTC

    You could use a quick shell like:

    for file in `find . -type f -print`;do cp $file $file~ ; cat $file |se +d -e 's/this/that/' > $; mv $ $file;done

    "Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://250472]
Approved by Paladin
[1nickt]: ... sign I have seen ...
[1nickt]: Now that one made me hopeful! First time not angry in a long time when I saw that kid.
[Discipulus]: i propend for removing: why? because we are so few that we must find i minimal common divisor, this is certainly Perl not our (anyway private) thougths. And i say this still wondering because i love a lot freedom of expression. And i say this not for roho
[1nickt]: Discipulus that was the point of my story of taking the sticker off my truck. I know there are lots of people in the world who if I knw their private beliefs I might want to argue with them. And they with me. But life cannot all be arguments!
[1nickt]: This is less than perfect ... but demanding perfection (from people or from life) is a sure way to unhappiness.
[Discipulus]: and anyway we have CB where every (democratic) opinion can be expressed
erix eat the rich!
[1nickt]: I do think it is sad that roho has received 3 downvotes for his polite request, as did I when I objected to the profanity in stonecolddevin's sig. I upvoted both him and Karl for the discussion. Way too much downvoting for inappropriate reasons here!
Discipulus learn that 'argue' has a little negative sense, he thought was a neutral sense, 'vox media'
[1nickt]: argue == discuss && argue == be contentious

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2017-06-22 12:18 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (519 votes). Check out past polls.