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

人走茶凉 提交于 2019-12-20 11:37:45

问题


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.


回答1:


Find files that has trailing spaces.

find . -type f -exec egrep -l " +$" {} \;



回答2:


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.




回答3:


Find files with one or more trailing space characters:

find . -name "*" | xargs egrep ".* +$"



回答4:


There is an option to list the files which do not contain a match anywhere in them; use that and a regex for a character other than a space just before end of line.

grep -L '[^ ]$' *

To recurse directories, add -r. To search for other whitespace characters as well, use a character class $'[^ \t]$' or the POSIX '[^[:blank:]]$' for the regex.




回答5:


Using ack (or ag):

ack -l ' \n'

Note: Like some of the other answers, this will list files that contain one or more lines with trailing spaces.




回答6:


If the goal is to list files with trailing whitespace in the current path:

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



回答7:


If the question is literally to find files that have a blank at the end of every single line, then this should work:

grep -rL '[^[:blank:]]$' .

The -L tells grep to report every file that does not match the pattern, and the pattern is looking for lines that do not have a blank immediately preceding the newline.




回答8:


Try this :

find . -type f -name "* "


来源:https://stackoverflow.com/questions/11210126/bash-find-files-with-trailing-spaces-at-the-end-of-the-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!