Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 670
Rey Avatar asked Dec 27 '22 06:12

Rey


1 Answers

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.

like image 83
Yanick Girouard Avatar answered May 13 '23 16:05

Yanick Girouard