Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/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
Unix 查找文件中的所有uniq字符串_Unix_Awk_Grep - Fatal编程技术网

Unix 查找文件中的所有uniq字符串

Unix 查找文件中的所有uniq字符串,unix,awk,grep,Unix,Awk,Grep,如果我有这样一个文件: find,apple,strg_sf,RTR,hand,mountain,stuff_about apple,find,not,here,key_board, core,chip,pro_ces, apple,core,strg_sf,RTR,key_board,not 我想输出文件中所有的唯一字符串 输出: find,apple,strg_sf,RTR,hand,mountain,stuff_about,not,here,key_board,core,chip,pro

如果我有这样一个文件:

find,apple,strg_sf,RTR,hand,mountain,stuff_about
apple,find,not,here,key_board,
core,chip,pro_ces,
apple,core,strg_sf,RTR,key_board,not
我想输出文件中所有的唯一字符串

输出:

find,apple,strg_sf,RTR,hand,mountain,stuff_about,not,here,key_board,core,chip,pro_ces

当我寻找唯一的字符串时,
sort
uniq
似乎只输出唯一的行

如果需要,您仍然可以使用sort和uniq:

$ <input.txt tr ',' '\n' | sort -u | paste -s -d , -
这样做的好处是使用更少的管道,代价是需要通过awk将整个列表加载到内存中的数组中,以确定哪些行是唯一的。请注意,a.s是,它不会在末尾打印换行符

$ <input.txt tr ',' '\n' | awk 'BEGIN{ORS=","}!a[$0]++'