1

ファイルから文字、小文字、大文字以外のものをすべて削除し、スペースに置き換える必要があります。次に例を示します。

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 
  • ファイルに通常とは異なる文字が含まれていることがあります。UTF-8 として保存されます。

文字以外をスペースに置き換えるにはどうすればよいですか?

4

4 に答える 4

3

Unicode 文字のサポートが必要な場合は(as mentioned in your question)、この perl コマンドですべてを置き換えますunicode non-letters

echo $line | perl -pe 's/[^\p{L}\s]+/ /g;'

参考: http: //www.regular-expressions.info/unicode.html

于 2012-05-11T23:33:56.930 に答える
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 
于 2012-05-11T23:10:43.103 に答える
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
于 2012-05-12T00:21:43.867 に答える
1

試す:

sed 's/[^A-Za-z]/ /g;' myfile.txt
于 2012-05-11T23:09:46.863 に答える