I have a load of CSS files in a folder and I want to be able to find and replace different values in all of these files in one go from the command line.
So, for example, if I wanted to replace colour #dadce4 with #ececec can this easily be done with a single command?
Just to be clear, I'm looking for something that will make the changes to all files within a directory and any sub directories without having to specify a file name.
-
2Use sedIpor Sircer– Ipor Sircer2017年11月26日 22:54:09 +00:00Commented Nov 26, 2017 at 22:54
2 Answers 2
You can use sed to find and replace text example :
sed -i 's/dadce4/ececec/g' file.css
The g
at the end means that it will replace all colours in the file!, not just first occurrence.
-
Thanks but I'm looking for something that will make the changes to all files within a directory and any sub directories without having to specify a file name.caned_monkey– caned_monkey2017年11月27日 09:53:41 +00:00Commented Nov 27, 2017 at 9:53
-
You can just pipe all the files you wantAsenM– AsenM2017年11月27日 12:30:23 +00:00Commented Nov 27, 2017 at 12:30
Run the following command to achieve the desired result.
awk '{gsub("dadce4","ececec",0ドル);print 0ドル}' filename >>output file
-
Thanks but I'm looking for something that will make the changes to all files within a directory and any sub directories without having to specify a file name.caned_monkey– caned_monkey2017年11月27日 09:53:53 +00:00Commented Nov 27, 2017 at 9:53
-
Use Below command it will works . Worked fine for me Find maindirectorypath/* -type f -exec sed -i "s/dadce4/ececec/g" {} \;Praveen Kumar BS– Praveen Kumar BS2017年11月27日 10:32:50 +00:00Commented Nov 27, 2017 at 10:32
-
@caned_monkey Kindly vote for my answer if its workingPraveen Kumar BS– Praveen Kumar BS2017年11月28日 05:17:11 +00:00Commented Nov 28, 2017 at 5:17
-
I've voted for your answer but because I'm a new user it wont change the visible score.caned_monkey– caned_monkey2017年11月28日 22:59:50 +00:00Commented Nov 28, 2017 at 22:59