如何在搜索字符串后准确删除 1 个单词?我可以删除搜索词,但不能删除之后的词,即“utf8”
# echo "varchar(255) CHARACTER SET utf8,"
varchar(255) CHARACTER SET utf8,
# echo "varchar(255) CHARACTER SET utf8," | sed 's/ CHARACTER SET[^ ]* / /g'
varchar(255) utf8,
预期输出:
varchar(255) ,
如何在搜索字符串后准确删除 1 个单词?我可以删除搜索词,但不能删除之后的词,即“utf8”
# echo "varchar(255) CHARACTER SET utf8,"
varchar(255) CHARACTER SET utf8,
# echo "varchar(255) CHARACTER SET utf8," | sed 's/ CHARACTER SET[^ ]* / /g'
varchar(255) utf8,
预期输出:
varchar(255) ,
echo "varchar(255) CHARACTER SET utf8," | sed 's/ CHARACTER SET [[:alnum:]]\+/ /g'
你是这个意思吗?
echo "varchar(255) CHARACTER SET utf8," | sed 's/ CHARACTER SET[ a-z0-9,]*/ /g'
输出
varchar(255)
这可能对您有用(GNU sed):
echo "varchar(255) CHARACTER SET utf8," | sed 's/ CHARACTER SET \w*/ /g'
echo "varchar(255) 字符集 utf8, aa" | sed 's/ 字符集.*,/ /g'