0

Hi I'm new to unix and trying to make a script that removes punctuation from user input using SED. But it isn't working.

read -p "Please enter a word or sentence: " word
sed -n 's/[^a-zA-Z ]//g' $word

if i enter abcd.,abcd it will give me an error "sed: can't read abcd,.abcd: No such file or directory"

So I guess that means it is treating the variable $word as a file instead of a string that I want it to process.

How would I fix this?

4

2 回答 2

2

sed将参数视为输入文件。

请尝试以下操作:

echo "$word" | sed -n 's/[^a-z]//ig'
于 2013-08-11T13:17:03.453 回答
1

这可能对你有用(bash):

sed 's/[^a-zA-Z ]//g' <<<"$word"

这利用了here-stringin bash。

于 2013-08-11T21:38:54.983 回答