0

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.

1

2 Answers 2

0

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.

2
  • 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. Nov 27, 2017 at 9:53
  • You can just pipe all the files you want
    – AsenM
    Nov 27, 2017 at 12:30
0

Please find below command to achieve the the result

awk '{gsub("dadce4","ececec”,$0);print $0}' filename >>output file
4
  • 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. 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” {} \; Nov 27, 2017 at 10:32
  • @caned_monkey Kindly vote for my answer if its working 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. Nov 28, 2017 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.