Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: find files with trailing spaces at the end of the lines

Tags:

I'm looking for a bash command to find files with trailing spaces at the end of each line. I'm not interested in removing the spaces, but just in finding the files.

like image 611
ziiweb Avatar asked Jun 26 '12 14:06

ziiweb


People also ask

How do you trim trailing spaces in bash?

`sed` command is another option to remove leading and trailing space or character from the string data. The following commands will remove the spaces from the variable, $myVar using `sed` command. Use sed 's/^ *//g', to remove the leading white spaces. There is another way to remove whitespaces using `sed` command.

How do I get rid of trailing space in Linux?

sed 's/\s\+$/ filename.


2 Answers

Find files that has trailing spaces.

find . -type f -exec egrep -l " +$" {} \; 
like image 107
pizza Avatar answered Oct 08 '22 05:10

pizza


If the goal is to list files which have trailing whitespaces in one or more lines:

grep -r '[[:blank:]]$' . 

To not print the lines, and print just the file names only, also specify the -l option. That's l as in the word list, not the number 1.

like image 28
Asclepius Avatar answered Oct 08 '22 05:10

Asclepius