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.
`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.
sed 's/\s\+$/ filename.
Find files that has trailing spaces.
find . -type f -exec egrep -l " +$" {} \;
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With