总的大写回报

时间:2019-03-15 09:55:16

标签: linux shell awk

以下命令显示wc -l的修改后的输出:

$ wc -l *.c *.h | awk '{print $2":"$1}'
file1.c:1000
file2.c:0
file3.h:5
total:1005

最后一行的单词total代表输出的总行数。有谁知道我可以更改该行以使其大写?

file1.c:1000
file2.c:0
file3.h:5
TOTAL:1005

4 个答案:

答案 0 :(得分:2)

这可以解决您的问题:

$ wc -l *.c *.h | awk '(NR>1){print t}{t=$2":"$1}END{print "TOTAL:"$1}'

comment of Ed Morton所示,此方法不像看起来那样健壮。可以在answer of stack0114106

中找到更强大的系统
$ wc -l *.c *.h | awk '(NR>1){print t1":"t2}{t1=$2;t2=$1}END{print "TOTAL:"t2}}'

但是您可以通过以下方式在GNU awk中完成全部操作:

$ awk 'ENDFILE{print FILENAME":"FNR}END{print "TOTAL:"NR}' *.c *.h

答案 1 :(得分:1)

另一个keypress

awk

或使用Perl

$ wc -l *.c *.h | awk '{ if(NR>1) print x; x=$2":"$1 } END { print toupper(x) } '
file1.c:4
file2.c:4
file3.h:3
TOTAL:11

$

答案 2 :(得分:0)

尝试一下:

tr [a-z] [A-Z] < "input file(s)".*

将文件内容打印到上方。否则,请尝试以下操作:

wc -l *.c *.h | awk '{print toupper($2)":"toupper($1)}'

不确定这是否行得通。

答案 3 :(得分:0)

awk '/total/{$1=toupper($1)}1' file

file1.c:1000
file2.c:0
file3.h:5
TOTAL:1005