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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PERL - all files in a directory

Status
Not open for further replies.

xoddam

Programmer
Mar 10, 2007
4
SK
Hello,

perl -p -i_ARCHIVE.txt -e "s/original/subst/g;" C:\test\testfile.txt

well i have this command. Yes its a easy substituence command, it works really good. It replaces the original word with the substitent AND creates a backup copy of the original in form : originalname_ARCHIVE.txt ...

Okay, and my question is ... HOW do i make it, that this command will be done for ALL files in specific directory ?

Lets say i have 1000 x *.txt files in directory "C:\test\" how do i make it? I tryed somethin like "C:\test\*.*" - did not worked ... I use WIN XP PRO :)


 
I learned this from one of the other experts here. I believe it was either ishnid or stevexff. Anyway, here's one solution.

Code:
perl -p -i_ARCHIVE.txt -e "BEGIN {@ARGV = <C:\test\*>}; s/int/subst/g;"

PS, There reaches a point when it is probably best to just use a script instead of a one-liner. But I suppose this does work.

- Miller
 
Slight Bug. Should have been:

Code:
>perl -p -i_ARCHIVE.txt -e "BEGIN {@ARGV = <C:/test/*>}; s/int/subst/g;"

- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top