简体   繁体   中英

Why is sed removing the greater than symbol

The less-than symbol is removed when I run my sed command.

a::b<type::value> & d
a::b<ns::type::value>& d
sed -i 's/[^:]type/changed::type/g'

results in

a::bchanged::type::value> & d
a::b<ns::type::value>& d

I expected to actually get the following:

a::b<changed::type::value> & d
a::b<ns::type::value>& d

Why is the less-than symbol removed? How can I keep it?

The symbol gets removed because it matches [^:] "not a colon", as part of the string to be replaced. You can bypass that by capturing it and putting it back:

sed -i 's/\([^:]\)type/\1changed::type/g'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM