4

This is a continuation of this question perhaps:

How to remove trailing whitespace of all files recursively?

I want to only remove whitespace for html / css / sass / whatever files I want.

Edit: whoops. I'm on Mac OS X Lion

Community
  • 1
  • 1
Rey
  • 3,639
  • 5
  • 33
  • 40
  • 3
    You should just be able to add the proper search pattern to find. Like find -name '\*.html' -or -name '\*.css', and the rest of it would be the same – vmpstr Feb 13 '12 at 17:23

1 Answers1

10

This worked for me to remove trailing whitespaces or tabs from all files in the ( ... ) section:

find . -type f \( -name "*.css" -o -name "*.html" -o -name "*.sass" \) -exec perl -p -i -e "s/[ \t]*$//g" "{}" \;

If you only want to remove whitespaces (and not tabs), then change s/[ \t]*$//g for s/ *$//g

If you want to change anything else, then just adjust the regex search and replace patterns to your liking. You should change the starting path of find to whatever path you want too.

David Cain
  • 16,484
  • 14
  • 65
  • 75
Yanick Girouard
  • 4,711
  • 4
  • 19
  • 26