在BOF或EOF中查找带有Blank或WS的所有文件 [英] Find all files with Blank or WS at BOF or EOF

查看:85
本文介绍了在BOF或EOF中查找带有Blank或WS的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人都知道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.

我试过这样的事情:

I tried something like this:

grep -r -e :a -e '/^\n*$/{$d;N;};/\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.

示例输出:

example output:

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中查找带有Blank或WS的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆