Remove occurrence of a pattern from string everywhere [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0
















This question already has an answer here:



  • How can I replace a string in a file(s)?

    7 answers



I want to remove occurrence of a string from a given string. Like /hello: from a string like /yo:/sup:/hello:/yo:/hello:/yup.

And one thing for sure if string contains a colon in end then it must be removed.



There can be anything between /hello and colon (:) so I want to strip all from /hello to first colon (:).










share|improve this question















marked as duplicate by Jesse_b, DopeGhoti, Mr Shunz, Jeff Schaller, Christopher Feb 15 at 18:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • actually there can be anything between /hello and : colon so I want to strip string from /hello to first match of colon

    – XeXkek
    Feb 15 at 15:32






  • 1





    Please show more examples of input that would demonstrate the various cases.

    – glenn jackman
    Feb 15 at 15:59






  • 1





    @XeXkek Welcome on U&L! Please, add all your requirements to your question (instead of adding them as comment to answers). It will make easier for other users to help you.

    – fra-san
    Feb 15 at 16:07











  • Is this i string embedded along with other text in a file, or do you have the string in a shell variable? Where is this string?

    – Kusalananda
    Feb 15 at 17:35











  • Yes in a shell variable called PATH

    – XeXkek
    Feb 15 at 18:27















0
















This question already has an answer here:



  • How can I replace a string in a file(s)?

    7 answers



I want to remove occurrence of a string from a given string. Like /hello: from a string like /yo:/sup:/hello:/yo:/hello:/yup.

And one thing for sure if string contains a colon in end then it must be removed.



There can be anything between /hello and colon (:) so I want to strip all from /hello to first colon (:).










share|improve this question















marked as duplicate by Jesse_b, DopeGhoti, Mr Shunz, Jeff Schaller, Christopher Feb 15 at 18:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • actually there can be anything between /hello and : colon so I want to strip string from /hello to first match of colon

    – XeXkek
    Feb 15 at 15:32






  • 1





    Please show more examples of input that would demonstrate the various cases.

    – glenn jackman
    Feb 15 at 15:59






  • 1





    @XeXkek Welcome on U&L! Please, add all your requirements to your question (instead of adding them as comment to answers). It will make easier for other users to help you.

    – fra-san
    Feb 15 at 16:07











  • Is this i string embedded along with other text in a file, or do you have the string in a shell variable? Where is this string?

    – Kusalananda
    Feb 15 at 17:35











  • Yes in a shell variable called PATH

    – XeXkek
    Feb 15 at 18:27













0












0








0









This question already has an answer here:



  • How can I replace a string in a file(s)?

    7 answers



I want to remove occurrence of a string from a given string. Like /hello: from a string like /yo:/sup:/hello:/yo:/hello:/yup.

And one thing for sure if string contains a colon in end then it must be removed.



There can be anything between /hello and colon (:) so I want to strip all from /hello to first colon (:).










share|improve this question

















This question already has an answer here:



  • How can I replace a string in a file(s)?

    7 answers



I want to remove occurrence of a string from a given string. Like /hello: from a string like /yo:/sup:/hello:/yo:/hello:/yup.

And one thing for sure if string contains a colon in end then it must be removed.



There can be anything between /hello and colon (:) so I want to strip all from /hello to first colon (:).





This question already has an answer here:



  • How can I replace a string in a file(s)?

    7 answers







text-processing sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 15 at 16:03









fra-san

1,8531519




1,8531519










asked Feb 15 at 15:28









XeXkekXeXkek

11




11




marked as duplicate by Jesse_b, DopeGhoti, Mr Shunz, Jeff Schaller, Christopher Feb 15 at 18:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Jesse_b, DopeGhoti, Mr Shunz, Jeff Schaller, Christopher Feb 15 at 18:19


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • actually there can be anything between /hello and : colon so I want to strip string from /hello to first match of colon

    – XeXkek
    Feb 15 at 15:32






  • 1





    Please show more examples of input that would demonstrate the various cases.

    – glenn jackman
    Feb 15 at 15:59






  • 1





    @XeXkek Welcome on U&L! Please, add all your requirements to your question (instead of adding them as comment to answers). It will make easier for other users to help you.

    – fra-san
    Feb 15 at 16:07











  • Is this i string embedded along with other text in a file, or do you have the string in a shell variable? Where is this string?

    – Kusalananda
    Feb 15 at 17:35











  • Yes in a shell variable called PATH

    – XeXkek
    Feb 15 at 18:27

















  • actually there can be anything between /hello and : colon so I want to strip string from /hello to first match of colon

    – XeXkek
    Feb 15 at 15:32






  • 1





    Please show more examples of input that would demonstrate the various cases.

    – glenn jackman
    Feb 15 at 15:59






  • 1





    @XeXkek Welcome on U&L! Please, add all your requirements to your question (instead of adding them as comment to answers). It will make easier for other users to help you.

    – fra-san
    Feb 15 at 16:07











  • Is this i string embedded along with other text in a file, or do you have the string in a shell variable? Where is this string?

    – Kusalananda
    Feb 15 at 17:35











  • Yes in a shell variable called PATH

    – XeXkek
    Feb 15 at 18:27
















actually there can be anything between /hello and : colon so I want to strip string from /hello to first match of colon

– XeXkek
Feb 15 at 15:32





actually there can be anything between /hello and : colon so I want to strip string from /hello to first match of colon

– XeXkek
Feb 15 at 15:32




1




1





Please show more examples of input that would demonstrate the various cases.

– glenn jackman
Feb 15 at 15:59





Please show more examples of input that would demonstrate the various cases.

– glenn jackman
Feb 15 at 15:59




1




1





@XeXkek Welcome on U&L! Please, add all your requirements to your question (instead of adding them as comment to answers). It will make easier for other users to help you.

– fra-san
Feb 15 at 16:07





@XeXkek Welcome on U&L! Please, add all your requirements to your question (instead of adding them as comment to answers). It will make easier for other users to help you.

– fra-san
Feb 15 at 16:07













Is this i string embedded along with other text in a file, or do you have the string in a shell variable? Where is this string?

– Kusalananda
Feb 15 at 17:35





Is this i string embedded along with other text in a file, or do you have the string in a shell variable? Where is this string?

– Kusalananda
Feb 15 at 17:35













Yes in a shell variable called PATH

– XeXkek
Feb 15 at 18:27





Yes in a shell variable called PATH

– XeXkek
Feb 15 at 18:27










2 Answers
2






active

oldest

votes


















0














With sed:



sed --in-place 's_/hello[^:]*:__g' inputfile





share|improve this answer























  • Bro it'll strips down string to last colon not only /helloblabal: I must remove till first match of colon if it is available

    – XeXkek
    Feb 15 at 15:35












  • Unable to replicate: echo "/yo:/sup:/hello:/yo:/hello:/yup" | sed 's_/hello[^:]*:__g' yields /yo:/sup:/yo:/yup.

    – DopeGhoti
    Feb 15 at 15:37











  • Also can colon be optional on first match?

    – XeXkek
    Feb 15 at 15:42












  • Making the rules for one match different from the rules for the rest of the matches means you're no longer talking about a regular expression, which means it's rather difficult to do as a quick one-off.

    – DopeGhoti
    Feb 15 at 15:57


















0














Perl in-line version:



perl -pi -e "s//hello//g" /path/to/file


or



perl -pi -e "s//hello://g" /path/to/file


If you want to remove the trailing : also.






share|improve this answer























  • It's not file it's a string

    – XeXkek
    Feb 15 at 18:04











  • echo /yo:/sup:/hello:/yo:/hello:/yup | perl -p -e 's//hello://g'

    – marc hurley
    Feb 18 at 9:23

















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














With sed:



sed --in-place 's_/hello[^:]*:__g' inputfile





share|improve this answer























  • Bro it'll strips down string to last colon not only /helloblabal: I must remove till first match of colon if it is available

    – XeXkek
    Feb 15 at 15:35












  • Unable to replicate: echo "/yo:/sup:/hello:/yo:/hello:/yup" | sed 's_/hello[^:]*:__g' yields /yo:/sup:/yo:/yup.

    – DopeGhoti
    Feb 15 at 15:37











  • Also can colon be optional on first match?

    – XeXkek
    Feb 15 at 15:42












  • Making the rules for one match different from the rules for the rest of the matches means you're no longer talking about a regular expression, which means it's rather difficult to do as a quick one-off.

    – DopeGhoti
    Feb 15 at 15:57















0














With sed:



sed --in-place 's_/hello[^:]*:__g' inputfile





share|improve this answer























  • Bro it'll strips down string to last colon not only /helloblabal: I must remove till first match of colon if it is available

    – XeXkek
    Feb 15 at 15:35












  • Unable to replicate: echo "/yo:/sup:/hello:/yo:/hello:/yup" | sed 's_/hello[^:]*:__g' yields /yo:/sup:/yo:/yup.

    – DopeGhoti
    Feb 15 at 15:37











  • Also can colon be optional on first match?

    – XeXkek
    Feb 15 at 15:42












  • Making the rules for one match different from the rules for the rest of the matches means you're no longer talking about a regular expression, which means it's rather difficult to do as a quick one-off.

    – DopeGhoti
    Feb 15 at 15:57













0












0








0







With sed:



sed --in-place 's_/hello[^:]*:__g' inputfile





share|improve this answer













With sed:



sed --in-place 's_/hello[^:]*:__g' inputfile






share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 15 at 15:31









DopeGhotiDopeGhoti

46.1k56089




46.1k56089












  • Bro it'll strips down string to last colon not only /helloblabal: I must remove till first match of colon if it is available

    – XeXkek
    Feb 15 at 15:35












  • Unable to replicate: echo "/yo:/sup:/hello:/yo:/hello:/yup" | sed 's_/hello[^:]*:__g' yields /yo:/sup:/yo:/yup.

    – DopeGhoti
    Feb 15 at 15:37











  • Also can colon be optional on first match?

    – XeXkek
    Feb 15 at 15:42












  • Making the rules for one match different from the rules for the rest of the matches means you're no longer talking about a regular expression, which means it's rather difficult to do as a quick one-off.

    – DopeGhoti
    Feb 15 at 15:57

















  • Bro it'll strips down string to last colon not only /helloblabal: I must remove till first match of colon if it is available

    – XeXkek
    Feb 15 at 15:35












  • Unable to replicate: echo "/yo:/sup:/hello:/yo:/hello:/yup" | sed 's_/hello[^:]*:__g' yields /yo:/sup:/yo:/yup.

    – DopeGhoti
    Feb 15 at 15:37











  • Also can colon be optional on first match?

    – XeXkek
    Feb 15 at 15:42












  • Making the rules for one match different from the rules for the rest of the matches means you're no longer talking about a regular expression, which means it's rather difficult to do as a quick one-off.

    – DopeGhoti
    Feb 15 at 15:57
















Bro it'll strips down string to last colon not only /helloblabal: I must remove till first match of colon if it is available

– XeXkek
Feb 15 at 15:35






Bro it'll strips down string to last colon not only /helloblabal: I must remove till first match of colon if it is available

– XeXkek
Feb 15 at 15:35














Unable to replicate: echo "/yo:/sup:/hello:/yo:/hello:/yup" | sed 's_/hello[^:]*:__g' yields /yo:/sup:/yo:/yup.

– DopeGhoti
Feb 15 at 15:37





Unable to replicate: echo "/yo:/sup:/hello:/yo:/hello:/yup" | sed 's_/hello[^:]*:__g' yields /yo:/sup:/yo:/yup.

– DopeGhoti
Feb 15 at 15:37













Also can colon be optional on first match?

– XeXkek
Feb 15 at 15:42






Also can colon be optional on first match?

– XeXkek
Feb 15 at 15:42














Making the rules for one match different from the rules for the rest of the matches means you're no longer talking about a regular expression, which means it's rather difficult to do as a quick one-off.

– DopeGhoti
Feb 15 at 15:57





Making the rules for one match different from the rules for the rest of the matches means you're no longer talking about a regular expression, which means it's rather difficult to do as a quick one-off.

– DopeGhoti
Feb 15 at 15:57













0














Perl in-line version:



perl -pi -e "s//hello//g" /path/to/file


or



perl -pi -e "s//hello://g" /path/to/file


If you want to remove the trailing : also.






share|improve this answer























  • It's not file it's a string

    – XeXkek
    Feb 15 at 18:04











  • echo /yo:/sup:/hello:/yo:/hello:/yup | perl -p -e 's//hello://g'

    – marc hurley
    Feb 18 at 9:23















0














Perl in-line version:



perl -pi -e "s//hello//g" /path/to/file


or



perl -pi -e "s//hello://g" /path/to/file


If you want to remove the trailing : also.






share|improve this answer























  • It's not file it's a string

    – XeXkek
    Feb 15 at 18:04











  • echo /yo:/sup:/hello:/yo:/hello:/yup | perl -p -e 's//hello://g'

    – marc hurley
    Feb 18 at 9:23













0












0








0







Perl in-line version:



perl -pi -e "s//hello//g" /path/to/file


or



perl -pi -e "s//hello://g" /path/to/file


If you want to remove the trailing : also.






share|improve this answer













Perl in-line version:



perl -pi -e "s//hello//g" /path/to/file


or



perl -pi -e "s//hello://g" /path/to/file


If you want to remove the trailing : also.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 15 at 16:00









marc hurleymarc hurley

1




1












  • It's not file it's a string

    – XeXkek
    Feb 15 at 18:04











  • echo /yo:/sup:/hello:/yo:/hello:/yup | perl -p -e 's//hello://g'

    – marc hurley
    Feb 18 at 9:23

















  • It's not file it's a string

    – XeXkek
    Feb 15 at 18:04











  • echo /yo:/sup:/hello:/yo:/hello:/yup | perl -p -e 's//hello://g'

    – marc hurley
    Feb 18 at 9:23
















It's not file it's a string

– XeXkek
Feb 15 at 18:04





It's not file it's a string

– XeXkek
Feb 15 at 18:04













echo /yo:/sup:/hello:/yo:/hello:/yup | perl -p -e 's//hello://g'

– marc hurley
Feb 18 at 9:23





echo /yo:/sup:/hello:/yo:/hello:/yup | perl -p -e 's//hello://g'

– marc hurley
Feb 18 at 9:23


Popular posts from this blog

How to check contact read email or not when send email to Individual?

Christian Cage

How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?