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]++'