如何在vim中运行awk以获得最长的行及其订单号?

时间:2016-05-13 01:01:12

标签: vim awk

我们可以通过命令获取最长行和订单号的长度:

 awk '{ print length(), NR, $0 | "sort -rn" }' /tmp/test.txt |head -n 1

现在,使用命令vim打开/tmp/test.txt。

:!awk '{ print length(), NR, $0 | "sort -rn" }' % |head -n 1

Press ENTER or type command to continue
head: cannot open ‘n’ for reading: No such file or directory
head: cannot open ‘1’ for reading: No such file or directory
sort: fflush failed: standard output: Broken pipe
sort: write error

如何解决?

1 个答案:

答案 0 :(得分:1)

你的命令效率很低。如果您还在使用awk,还应该让它计算最长行的长度:

 awk '{ l = length($0); a = (a > l) ? a : l } END {print a}' test.txt
相关问题