Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
File 使用linux命令打印文件中的重复条目_File_Shell_Sorting_Unix_Uniq - Fatal编程技术网

File 使用linux命令打印文件中的重复条目

File 使用linux命令打印文件中的重复条目,file,shell,sorting,unix,uniq,File,Shell,Sorting,Unix,Uniq,我有一个名为foo.txt的文件,其中包括: abc zaa asd dess zaa abc aaa zaa 我希望输出存储在另一个文件中,如下所示: this text abc appears 2 times this text zaa appears 3 times 我尝试了下面的命令,但这只是写入重复的条目及其编号 sort foo.txt | uniq --count --repeated > sample.txt 上述命令的输出示例: abc 2 zaa 3 如何添加“

我有一个名为foo.txt的文件,其中包括:

abc
zaa
asd
dess
zaa
abc
aaa
zaa
我希望输出存储在另一个文件中,如下所示:

this text abc appears 2 times
this text zaa appears 3 times
我尝试了下面的命令,但这只是写入重复的条目及其编号

sort foo.txt | uniq --count --repeated > sample.txt
上述命令的输出示例:

abc 2
zaa 3
如何添加“此文本显示x次”一行?

Awk是您的朋友:

sort foo.txt | uniq --count --repeated | awk '{print($2" appears "$1" times")}'
Awk是你的朋友:

sort foo.txt | uniq --count --repeated | awk '{print($2" appears "$1" times")}'

谢谢!!工作得很好谢谢!!运作良好