unix中使用grep命令
问题描述:
我有一个文件,我想根据单词排序并删除特殊字符。 grep命令用于搜索的字符unix中使用grep命令
-b Display the block number at the beginning of each line.
-c Display the number of matched lines.
-h Display the matched lines, but do not display the filenames.
-i Ignore case sensitivity.
-l Display the filenames, but do not display the matched lines.
-n Display the matched lines and their line numbers.
-s Silent mode.
-v Display all lines that do NOT match.
-w Match whole word
但 如何使用grep命令做file sort
和remove the special character
和数量。
答
在所有文件中搜索grep以查找匹配的文本。它并没有真正的排序,也没有真正的切割和改变输出。你想要什么可能是使用sort命令
sort <filename>
并送往要么awk命令或sed命令的输出,这是处理文本的常用工具。
sort <filename> | sed 's/REPLACE/NEW_TEXT/g'
上面的东西我想象。
答
以下命令可以做到这一点。
sort FILE | tr -d 'LIST OF SPECIAL CHARS' > NEW_FILE
我认为这不是一个可以理解的问题,更不用说它几乎可以肯定是脱离了SO的主题。 – NPE 2012-02-05 12:36:36
sort命令会对它进行排序并将其管理到grep或sed,并用正则表达式去除你的字符 – 2012-02-05 12:38:20
定义'按照单词'和'特殊字符'进行排序 – 2012-02-05 12:59:39