删除文件中的特定符号

时间:2014-05-13 18:14:54

标签: linux

我有问题。我有这种格式的文件:

Hi / Tom /
Be / Nice /
...

我需要删除“/”和“”(空格)并对其进行排序

Be Nice
Hi Tom
...

2 个答案:

答案 0 :(得分:1)

for sorted_word in $(for word in $(sed  -e 's/\/ //g' path_to_file); do printf "%s\n" ${word}; done | sort); do printf "%s " ${sorted_word}; done ; printf "%s\n"

答案 1 :(得分:1)

您可以使用tr命令,如

cat inputfile.txt | tr -s "\/" "" | tr " " "\n" | sort | tr "\n" " "