【发布时间】:2017-05-11 13:45:52
【问题描述】:
我有一个如下示例文件。有引导行空格。有没有办法检测它们并使用 shell 脚本打印包含行空间的确切行号?
test space at back
test space at front
TAB at end
TAB at front
【问题讨论】:
标签: linux shell centos ubuntu-14.04 text-processing
我有一个如下示例文件。有引导行空格。有没有办法检测它们并使用 shell 脚本打印包含行空间的确切行号?
test space at back
test space at front
TAB at end
TAB at front
【问题讨论】:
标签: linux shell centos ubuntu-14.04 text-processing
grep 可以用 [:blank:] 查找空白,用 ^(正则表达式)查找行首
grep -n 将打印行号
试试grep -n '^[[:blank:]]' filename
【讨论】:
这对我有用! 如果 grep -n '^' config.js /dev/null >&2;然后 echo "$0: 上面标识的前导空格;正在中止" >&2 1号出口 菲
【讨论】: