D
Daryl Rose
I need to edit 100 or more shell scripts. These shell scripts have
been moved, and they have a single line in them that define a specific
path. i.e. FILEDIR="/opt/<subdir>/file"
This path needs to be changed. The opt directory is the only
consistent within this path. The name of the subdir, and the file
name change.
I do almost all of my work in shell, I rarely ever use PERL, but I
feel perl would be the best solution for this purpose. I know that I
can use the substitute operator to change this line without a bunch of
messy redirects and move commands to rename the files.
The way that I was planning on doing this was something like:
find . -exec grep -l <string here> {} ;/ |while read line
do
var1=`echo $line |awk -F"/" '{print $3}'` # get the subdir name.
var2=`echo $line |awk -F"/" '{print $4}'` # get the file name.
perl -ip -e 's/SEARCH/REPLACE/' $var1/$var2
done
The problem that I am having is the SEARCH and REPLACE strings. Since
the subdir and file name are going to change within each file, I'm not
sure how to pass the variables into the substitute command. Could one
of you perl experts give me a suggestion on how to do this?
Thank you.
Daryl Rose
been moved, and they have a single line in them that define a specific
path. i.e. FILEDIR="/opt/<subdir>/file"
This path needs to be changed. The opt directory is the only
consistent within this path. The name of the subdir, and the file
name change.
I do almost all of my work in shell, I rarely ever use PERL, but I
feel perl would be the best solution for this purpose. I know that I
can use the substitute operator to change this line without a bunch of
messy redirects and move commands to rename the files.
The way that I was planning on doing this was something like:
find . -exec grep -l <string here> {} ;/ |while read line
do
var1=`echo $line |awk -F"/" '{print $3}'` # get the subdir name.
var2=`echo $line |awk -F"/" '{print $4}'` # get the file name.
perl -ip -e 's/SEARCH/REPLACE/' $var1/$var2
done
The problem that I am having is the SEARCH and REPLACE strings. Since
the subdir and file name are going to change within each file, I'm not
sure how to pass the variables into the substitute command. Could one
of you perl experts give me a suggestion on how to do this?
Thank you.
Daryl Rose