简体   繁体   中英

Remove integer from each line with sed

I have a list of strings that I want to remove the number and colon from the beginning of every string. How can I do this with sed ?

When using:

printf '%s\n' '1:I am a sample line 1: line' '2:schafe' '11:11:11:12:' 'a'"'" | sed 's/^[0-9]\://g'

I would like to end up with:

I am a sample line 1: line
schafe
11:11:12:
a'

however running the command above seems to leave the 11:11:11:12: line untouched. I'd like sed to match any size number if possible.

I am using BSD sed (from macOS) but I also have access to GNU sed if that is necessary.

Thanks

Thanks to Beta and potong :

sed 's/^[0-9][0-9]*://'

This will match either one or more numbers before a : .

sed 's/^[0-9]*://' was originally used, however this could also match strings containing a : at the beginning (no number).

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