Rey
Rey

Reputation: 3767

How To Removing Trailing Whitespace Of All Files of selective file types in a directory recursively?

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

Upvotes: 4

Views: 2231

Answers (1)

Yanick Girouard
Yanick Girouard

Reputation: 4960

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.

Upvotes: 10

Related Questions