I have large number of files that have an deprecated css value "hspace" and I want to change it with other css style value. Here is an example: we have:


and we want to change with:

style="margin: 0 5px;"

each file has different value inside hspace, one can be hspace='5' other hspace='2', hspace='7' and so on.

what I want is find in all files in specific directory:

hspace='ANY NUMBER'

and replace with:

style="margin: 0 5px;"

Any suggestion to do this in bash centos os?

  • hspice='8' => will be transformed into what?
    – user218374
    Commented Apr 6, 2017 at 16:49
  • with style="margin: 0 8px;" Commented Apr 6, 2017 at 17:21
  • Then you need to edit your main theme where you are stating that: hspace='ANY NUMBER' to replace with: style="margin: 0 5px;"
    – user218374
    Commented Apr 6, 2017 at 22:14

1 Answer 1


You can use this command for replacing (assuming GNU sed as found on CentOS):

sed -i "s/hspace='\([0-9]*\)'/style=\"margin: 0 \1px;\"/g" filename.html

To replace in all .html-files:

find . -type f -name '*.html' -exec sed -i "s/hspace='\([0-9]*\)'/style=\"margin: 0 \1px;\"/g" {} +
  • in my case files don't have extension. I tried to use '*' instead of '*.html' but doesn't work Commented Apr 6, 2017 at 14:51
  • ok, seems that @Stéphane-Chazelas changed last solution and now it works perfectly. Thanks Commented Apr 6, 2017 at 14:54
  • Sorry, i should have checked it before publishing. Thanks to @Stéphane Chazelas for edits.
    – ValeriyKr
    Commented Apr 7, 2017 at 19:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .