我正在尝试翻译(Tr)一个字符串,将两个字符的组合替换为逗号。
字符串:- input is "test-1 - test-2 - test-3"所需的输出为"test-1 ,test-2 ,test-3"
为此,我需要将“-”空格+ '-‘替换为逗号,
我尝试了以下选项
$ echo "test-1 - test-2 - test-3" | tr '-[:space:]' ','
$ echo "test-1 - test-2 - test-3" | tr '- ' ','但是抛出一个错误?,它适用于任何其他两个字符的组合,但不能使用空格?
发布于 2015-12-10 18:25:25
您可以使用sed而不是tr来实现此目的:
$ echo "test-1 - test-2 - test-3" | sed "s/ - / ,/g"https://stackoverflow.com/questions/34199286
复制相似问题