2012-05-11 14 views
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として保存されます。

どのように非文字をスペースで置き換えることができますか?

答えて

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 
1

試してください:あなたはユニコード文字(as mentioned in your question)のためにサポートしたい場合は、このPerlコマンドは交換する

sed 's/[^A-Za-z]/ /g;' myfile.txt 
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 
+0

+1 [:アルファ:]' –

関連する問題