wfxr
9/28/2016 - 3:23 AM

complex-command-examples.md

eg1: 找出dictionary.txt中所有的变位词

make && ./sign < dictionary.txt | sort | ./squash | awk '{print NF,$0}' | sort -nr | sed -e '/^1/d' -e 's/ *$//g' | cut -d ' ' -f 2- > gramlist.txt

以上命令首先用make编译程序signsquash,然后运行sign(将dictionary.txt的内容重定向为sign程序的输入流),sign的输出通过管道提供给sort命令进行排序;排序后的流作为squash程序的输入流,输出流通过管道提供给awk,在每一行的开始位置加入此行的字段总数,然后再使用sort按字段数进行降序排列,排序后执行sed命令,删除字段数为1的行以及行末的空字符,接着使用cut删除之前加到行首的字段总数,将结果重定向到gramlist.txt文件