Reputation: 32326
How do I remove all the words starting from COMMENT word in the following string?
echo "first_mail_sent_date_time datetime NOT NULL COMMENT 'The date and time'," | sed 's/ COMMENT \w*/ /g'
The above sed command will remove only the word COMMENT. I need to remove everything after COMMENT but keep the last comma.
I can use awk but I am looking for sed solution for consistency sake.
awk -F'COMMENT' '{print $1 ","}'
Upvotes: 1
Views: 11630
Reputation: 785196
Use this sed command:
sed "s/ COMMENT.*'[^']*'/ /"
TEST:
str="first_mail_sent_date_time datetime NOT NULL COMMENT 'The date and time'FOO,"
echo $str | sed "s/ COMMENT.*'[^']*'/ /"
OUTPUT:
first_mail_sent_date_time datetime NOT NULL FOO,
Upvotes: 1