Command used for the job: egrep -rl ' $' --include *.c --include *.h --include *.s --include *.inc --include *.txt * | xargs sed -i 's/\s\+$//g' Credits to Grant Murphy from Stack Overflow.