Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell Linux grep管道_Shell_Pipe - Fatal编程技术网

Shell Linux grep管道

Shell Linux grep管道,shell,pipe,Shell,Pipe,我有一个input.txt文件,其中包含一个编号列表: 1719 194 1719 1719 194 1135 194 我想使用grep管道创建output.txt,以便按照外观数量的升序对它们进行排序,即: 194: 3 times 1719: 2 times 1135: 1 time. 有什么建议吗?假设数字在6910460.txt中,没有空行: $ cat 6910460.txt | sort | uniq -c | sort -nr 3 194 2 1719 1 1135 或者,

我有一个input.txt文件,其中包含一个编号列表:

1719
194
1719
1719
194
1135
194
我想使用grep管道创建output.txt,以便按照外观数量的升序对它们进行排序,即:

194: 3 times
1719: 2 times
1135: 1 time.

有什么建议吗?

假设数字在6910460.txt中,没有空行:

$ cat 6910460.txt | sort | uniq -c | sort -nr
3  194
2 1719
1 1135
或者,如果还需要文本“times”,可以附加一个awk命令:

$ cat 6910460.txt | sort | uniq -c | sort -nr | \
    awk 'BEGIN {FS=OFS=" "} \
        {temp=$2; $2=$1; $1=temp} {printf "%4i %4i time(s)\n", $1, $2}'
将打印:

 194    3 time(s)
1719    2 time(s)
1135    1 time(s)

假设数字在6910460.txt中,没有空行:

$ cat 6910460.txt | sort | uniq -c | sort -nr
3  194
2 1719
1 1135
或者,如果还需要文本“times”,可以附加一个awk命令:

$ cat 6910460.txt | sort | uniq -c | sort -nr | \
    awk 'BEGIN {FS=OFS=" "} \
        {temp=$2; $2=$1; $1=temp} {printf "%4i %4i time(s)\n", $1, $2}'
将打印:

 194    3 time(s)
1719    2 time(s)
1135    1 time(s)
这是否足够,或者您可以自己切换值


这就足够了吗,或者你可以自己切换值吗?

我手头没有Linux,但是我想这样做:

cat input.txt | sort | uniq -c | sort -g

目前我手头还没有Linux,但我想做这样的工作:

cat input.txt | sort | uniq -c | sort -g

由于出现频率都是整数,因此没有真正的理由在
sort-g
中使用较慢的浮点。坚持使用
-n
。因为出现频率都是整数,所以没有真正的理由在
排序-g
中使用较慢的浮点。坚持使用
-n