script to change unix path to windows path in all files
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
script to change unix path to windows path in all files
I need a shell script to recursively read through a directory and change all instances in a program of /var/www/html/ to /www/Apache2/htdocs/. Additionally I want it to print the full path and name of the file it changed. I can use bash or csh or even perl.
yes, I am trying to read each file and change every occurance of /var/www/html to /www/Apache2/htdocs. I do not script so I was hoping someone had such a script.
Ok, you can do this then. Run this in the dir where the files are:
Code:
#!/bin/bash
for i in `find .`
do
if [ -f $i ]; then
grepResult=`cat $i | grep "/www/Apache2/htdocs/"`
if [ -z "$grepResult" ]; then
echo $i
cat $i | sed 's/\/var\/www\/html\//\/www\/Apache2\/htdocs\//' > $i
fi
fi
done
#!/bin/bash
for i in `find . -type f`
do
if [ -f $i ]; then
grepResult=`cat $i | grep "/www/Apache2/htdocs/"`
if [ -z "$grepResult" ]; then
echo $i
cat $i | sed 's/\/var\/www\/html\//\/www\/Apache2\/htdocs\//' > $i
fi
fi
done
the -type f switch makes find only list files, not dirs.
burnin, "should" is a bit strong eh? My original code works. The line "if [ -f $i ];." Actually, your way convolutes it, its redudant. If you added "-type f," you could get rid of the "if [ -f $i ]," business.
Its a style choice, I prefer to add a restriction that way.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.