My intentions is to make all *.less files into style.css
I am not very familiar with this sed, however I have worked this out thanks to:
http://forums.devshed.com/unix-help-35/unix-find-and-replace-text-within-all-files-within-a-146179.html
for file in $(grep -rl ".less" *.php)
do
sed -e "s/\/*.less/\/style.css/ig" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
done
Now this takes my files:
css/somefile.less
css/somefileagain.less
css/style.css
index.php
which is linked to in the php document
<link rel="stylesheet" type="text/css" href="css/somefile.less" />
<link rel="stylesheet" type="text/css" href="css/somefileagain.less" />
My result becomes
<link rel="stylesheet" type="text/css" href="css/somefile/style.css" />
<link rel="stylesheet" type="text/css" href="css/somefileagain/style.css" />
Which is not what I want. I want to get it to be the same path, and I think what I am missing is the * in the regexp which isn’t replaced by the sed. Is there any way to get that working, my try was to make it look like this: (and I want to replace everything from / to .less with /style.css)
\/*.less
And still that doesn’t work, maybe this approach is not the best, I need some advices if there is any flags that would replace the * as well, thanks.
Another issue I got is I cannot use -r/-R/–recursive in grep and I dont know why, I am running Debian. Any tips is appreciated.
/Marcus
You need to use following sed command inside your for loop:
No need to store sed’s output in a separate file and then mv that temp file back to original. All this can be done with
-ioption.