Removing part of a string before a pattern

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











up vote
2
down vote

favorite












Am trying to use the sed command to remove all the text before the first numeric character in all the lines, by using the following



sed 's/.*[0-9]//' temp1.txt


However, it is removing all the text up to the last numeric character.







share|improve this question




















  • you should add sample input/output to clarify whether or not you want to remove the first digit as well... you text says before but the code you tried removes the digit
    – Sundeep
    Oct 28 '17 at 15:25










  • see also stackoverflow.com/questions/5319840/…
    – Sundeep
    Oct 28 '17 at 15:25














up vote
2
down vote

favorite












Am trying to use the sed command to remove all the text before the first numeric character in all the lines, by using the following



sed 's/.*[0-9]//' temp1.txt


However, it is removing all the text up to the last numeric character.







share|improve this question




















  • you should add sample input/output to clarify whether or not you want to remove the first digit as well... you text says before but the code you tried removes the digit
    – Sundeep
    Oct 28 '17 at 15:25










  • see also stackoverflow.com/questions/5319840/…
    – Sundeep
    Oct 28 '17 at 15:25












up vote
2
down vote

favorite









up vote
2
down vote

favorite











Am trying to use the sed command to remove all the text before the first numeric character in all the lines, by using the following



sed 's/.*[0-9]//' temp1.txt


However, it is removing all the text up to the last numeric character.







share|improve this question












Am trying to use the sed command to remove all the text before the first numeric character in all the lines, by using the following



sed 's/.*[0-9]//' temp1.txt


However, it is removing all the text up to the last numeric character.









share|improve this question











share|improve this question




share|improve this question










asked Oct 28 '17 at 15:07









thefinn

112




112











  • you should add sample input/output to clarify whether or not you want to remove the first digit as well... you text says before but the code you tried removes the digit
    – Sundeep
    Oct 28 '17 at 15:25










  • see also stackoverflow.com/questions/5319840/…
    – Sundeep
    Oct 28 '17 at 15:25
















  • you should add sample input/output to clarify whether or not you want to remove the first digit as well... you text says before but the code you tried removes the digit
    – Sundeep
    Oct 28 '17 at 15:25










  • see also stackoverflow.com/questions/5319840/…
    – Sundeep
    Oct 28 '17 at 15:25















you should add sample input/output to clarify whether or not you want to remove the first digit as well... you text says before but the code you tried removes the digit
– Sundeep
Oct 28 '17 at 15:25




you should add sample input/output to clarify whether or not you want to remove the first digit as well... you text says before but the code you tried removes the digit
– Sundeep
Oct 28 '17 at 15:25












see also stackoverflow.com/questions/5319840/…
– Sundeep
Oct 28 '17 at 15:25




see also stackoverflow.com/questions/5319840/…
– Sundeep
Oct 28 '17 at 15:25










1 Answer
1






active

oldest

votes

















up vote
2
down vote













this is due to eager algorithm of sed.



use:



sed 's/^[^0-9]*//' temp1.txt


where




  • ^ begining of line


  • [^0-9] any char but 0-9


  • * multiple time





share|improve this answer


















  • 1




    This will also remove the first numeric character, if this is not desired, leave off the second [0-9]
    – crater2150
    Oct 28 '17 at 15:17










  • @crater2150 edited, thanks.
    – Archemar
    Oct 28 '17 at 15:38










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401076%2fremoving-part-of-a-string-before-a-pattern%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













this is due to eager algorithm of sed.



use:



sed 's/^[^0-9]*//' temp1.txt


where




  • ^ begining of line


  • [^0-9] any char but 0-9


  • * multiple time





share|improve this answer


















  • 1




    This will also remove the first numeric character, if this is not desired, leave off the second [0-9]
    – crater2150
    Oct 28 '17 at 15:17










  • @crater2150 edited, thanks.
    – Archemar
    Oct 28 '17 at 15:38














up vote
2
down vote













this is due to eager algorithm of sed.



use:



sed 's/^[^0-9]*//' temp1.txt


where




  • ^ begining of line


  • [^0-9] any char but 0-9


  • * multiple time





share|improve this answer


















  • 1




    This will also remove the first numeric character, if this is not desired, leave off the second [0-9]
    – crater2150
    Oct 28 '17 at 15:17










  • @crater2150 edited, thanks.
    – Archemar
    Oct 28 '17 at 15:38












up vote
2
down vote










up vote
2
down vote









this is due to eager algorithm of sed.



use:



sed 's/^[^0-9]*//' temp1.txt


where




  • ^ begining of line


  • [^0-9] any char but 0-9


  • * multiple time





share|improve this answer














this is due to eager algorithm of sed.



use:



sed 's/^[^0-9]*//' temp1.txt


where




  • ^ begining of line


  • [^0-9] any char but 0-9


  • * multiple time






share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 28 '17 at 15:37

























answered Oct 28 '17 at 15:14









Archemar

19k93366




19k93366







  • 1




    This will also remove the first numeric character, if this is not desired, leave off the second [0-9]
    – crater2150
    Oct 28 '17 at 15:17










  • @crater2150 edited, thanks.
    – Archemar
    Oct 28 '17 at 15:38












  • 1




    This will also remove the first numeric character, if this is not desired, leave off the second [0-9]
    – crater2150
    Oct 28 '17 at 15:17










  • @crater2150 edited, thanks.
    – Archemar
    Oct 28 '17 at 15:38







1




1




This will also remove the first numeric character, if this is not desired, leave off the second [0-9]
– crater2150
Oct 28 '17 at 15:17




This will also remove the first numeric character, if this is not desired, leave off the second [0-9]
– crater2150
Oct 28 '17 at 15:17












@crater2150 edited, thanks.
– Archemar
Oct 28 '17 at 15:38




@crater2150 edited, thanks.
– Archemar
Oct 28 '17 at 15:38

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401076%2fremoving-part-of-a-string-before-a-pattern%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

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

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?