Bash
如何刪除我的文件中的字元串?
如何刪除或刪除字元串。所以基本上我想刪除下面的整個字元串
[MTT-5634](https://my.atlassian.net/browse/MTT-5634)
我努力了
sed -e 's/\[(MTT|MCC)-[0-9]{3,4}\?]\?://g;s!.\?http[s]\?://\S*!!g' input.txt > output.txt
輸出
[MTT-5634]
預期產出
When you didn't enable the
-Extended regex, so you will need to escapes a few special character such as
(,
),
|,
{,
},
?. you also have a trailing
:in your first sed statement that should be removed. Also you forgot to escape the closing bracket
]`.your own corrected (but not improved) command should be:
sed -e 's/\[\(MTT\|MCC\)-[0-9]\{3,4\}\?\]\?//g;s!.\?http[s]\?://\S*!!g' infile
see What characters do I need to escape when using sed in a sh script?`