問題描述
每個人都知道 PHP 討厭在文件的開頭或結尾(在 PHP 標簽之前或之后)出現空行.
Everyone knows PHP hates blank lines at the beginning or end of a file (before or after the PHP tags).
我有一個 awk
腳本可以修改文件.我通過它傳遞了我的所有文件,一切都很好,沒有更多的前導或尾隨空行.
I've got an awk
script that will modify the files. I pass all my files through it and things are peachy, no more leading or trailing blank lines.
我想先查找文件,以構建快速異常報告.
I'd like to FIND the files first, to build a quick exception report.
我嘗試過這樣的事情:
grep -r -e :a -e '/^
*$/{$d;N;};/
$/ba'
但那是錯誤的.
推薦答案
此 shell 腳本將遍歷您的所有文件,并在每個文件的開頭或結尾找到空行時進行打印:
This shell script will go through all your files and print if it found a blank line at the beginning or end of each file:
for f in `find . -type f`; do
for t in head tail; do
$t -1 $f |egrep '^[ ]*$' >/dev/null && echo "blank line at the $t of $f";
done;
done
為了可讀性我打破了線條,但你也可以將它作為單行運行.
I broke the lines for readability, but you can run it as a one liner too.
示例輸出:
blank line at the head of ./b
blank line at the tail of ./c
blank line at the head of ./d
blank line at the tail of ./d
這篇關于在 BOF 或 EOF 中查找所有帶有空白或 WS 的文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!