我有一个文件,我想根据一个单词对其进行排序并删除特殊字符。 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
以及编号。
答案 0 :(得分:2)
grep在所有文件中搜索以查找匹配的文本。它并没有真正排序,它并没有真正切断和改变输出。你想要的可能是使用sort命令
sort <filename>
并将输出发送到awk命令或sed命令,这些是操作文本的常用工具。
sort <filename> | sed 's/REPLACE/NEW_TEXT/g'
像我想象的那样。
答案 1 :(得分:2)
以下命令可以执行此操作。
sort FILE | tr -d 'LIST OF SPECIAL CHARS' > NEW_FILE