简体   繁体   中英

How to remove first character up to a specific character in a string using bash scripting?

For example, I have a string:

HelloWorld: This is HelloWorld: another HelloWorld

How do I get from the above string to just

This is HelloWorld: another Helloworld

There can also be whitespaces in the beginning of the full string, and basically I just want to remove all characters up to the first occurance of the first colon (":") in the string.

Thanks for the help!

string="HelloWorld: This is HelloWorld: another HelloWorld"

With a POSIX shell (useful when the string is already in a variable):

echo "${string#*: }"

With sed:

echo "$string" | sed 's/^[^:]*: //'

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