wicus
June 1, 2012, 4:48am
1
I need to update about 2400 files in a directory subtree, with a new directory path inside the files
I need to change this occurence in all files: /d2/R12AB/VIS/apps/tech_st/10.1.2
with this: /u01/PROD/apps/apps_st/10.1.3
I know how to change single words using "find . -type f -print0 | xargs -0 sed -i 's/old_word/new_word/g'", but I've never worked with replacing multiple words at once.
what is the your all words?
for exa : old_word --> new_word
and the others ?
wicus
June 1, 2012, 5:01am
3
I need to replace this string in all files: /d2/R12AB/VIS/apps/tech_st/10.1.2
with this new string: /u01/PROD/apps/apps_st/10.1.3
find . -type f -print0|while read -r file; do
sed 's|/d2/R12AB/VIS/apps/tech_st/10.1.2|/u01/PROD/apps/apps_st/10.1.3|g' $file > ${file}.tmp && mv -f ${file}.tmp $file
done
wicus
June 1, 2012, 5:20am
5
Thank you, I've tested this limiting it only to .sh files , but it don't seem to do anything:
.
[root@rh5u8-ebs1206 tmp]# grep R12AB *.sh | wc -l
11
[root@rh5u8-ebs1206 tmp]# find . -type f -name '*.sh' -print0|while read -r file; do
> sed 's|/d2/R12AB/ab/apps/FINVIS19/apps/tech_st/10.1.2|/u01/PROD/apps/apps_st/10.1.2|g' $file > ${file}.tmp && mv -f ${file}.tmp $file
> done
[root@rh5u8-ebs1206 tmp]# grep R12AB *.sh | wc -l
8
[root@rh5u8-ebs1206 tmp]# grep u01 *.sh | wc -l
0
[root@rh5u8-ebs1206 tmp]# grep '/d2/R12AB/ab/apps/FINVIS19/apps/tech_st/10.1.2' *.sh | wc -l
8
[root@rh5u8-ebs1206 tmp]#
wicus:
Thank you, I've tested this limiting it only to .sh files , but it don't seem to do anything:
.
[root@rh5u8-ebs1206 tmp]# grep R12AB .sh | wc -l
11
[root@rh5u8-ebs1206 tmp]# find . -type f -name ' .sh' -print0|while read -r file; do
> sed 's|/d2/R12AB/ab/apps/FINVIS19/apps/tech_st/10.1.2|/u01/PROD/apps/apps_st/10.1.2|g' $file > ${file}.tmp && mv -f ${file}.tmp $file
> done
[root@rh5u8-ebs1206 tmp]# grep R12AB *.sh | wc -l
8
[root@rh5u8-ebs1206 tmp]# grep u01 *.sh | wc -l
0
[root@rh5u8-ebs1206 tmp]# grep '/d2/R12AB/ab/apps/FINVIS19/apps/tech_st/10.1.2' *.sh | wc -l
8
[root@rh5u8-ebs1206 tmp]#
remove the "-print0"
find . -name '*.sh' -type f|while read -r file; do
sed 's|/d2/R12AB/VIS/apps/tech_st/10.1.2|/u01/PROD/apps/apps_st/10.1.3|g' $file > ${file}.tmp && mv -f ${file}.tmp $file
done
wicus
June 1, 2012, 6:51am
7
Thank you, removing the "-print0" did the trick. Much appreciated.