in reply to Re: Replacing a string in a file
in thread Replacing a string in a file
perl -ne 's!/xxx/yyy/zzz!$ENV{FILE_DIR_PATH}!g' file.txt
This won't do anything. You are quietly looping over the lines in file.txt, setting $_ in turn, performing the substitution, and going to the next line. If you change the -n option to -p, then at least you are printing the 'new' file to STDOUT, and you could redirect to a file:
perl -pe 's!/xxx/yyy/zzz!$ENV{FILE_DIR_PATH}!g' file.txt > new_file.txt
But in truth, Tom_Slick_Adv probably wants the -i switch, which modifies the file in place:
perl -pi.bak -e's!/xxx/yyy/zzz!$ENV{FILE_DIR_PATH}!g' file.txt
This will back-up the original file with the extension '.bak'. See perlman:perlrun for more info.
--
|
|---|