我需要从文件中删除所有非字母,小写或大写的内容,并将其替换为空格,例如:
The bear ate 3 snakes, then ate 50% of the fish from the river.
这变为:
The bear ate snakes then ate of the fish from the river
如何用空格替换任何非字母?
答案 0 :(得分:3)
如果你想支持unicode字母(as mentioned in your question)
,那么这个perl命令可以替换所有unicode non-letters
:
echo $line | perl -pe 's/[^\p{L}\s]+/ /g;'
答案 1 :(得分:2)
$ echo "The bear ate 3 snakes, then ate 50% of the fish from the river." | sed "s/[^a-zA-Z]/ /g"
The bear ate snakes then ate of the fish from the river
答案 2 :(得分:2)
这可能对您有用:
echo 'The bear ate 3 snakes, then ate 50% of the fish from the river.' |
tr -c '[:alpha:]' ' '
The bear ate snakes then ate of the fish from the river
或:
echo 'The bear ate 3 snakes, then ate 50% of the fish from the river.' |
sed 's/[^[:alpha:]]/ /g'
The bear ate snakes then ate of the fish from the river
答案 3 :(得分:1)
尝试:
sed 's/[^A-Za-z]/ /g;' myfile.txt