How to remove specific numbers from a txt file with SED or AWK?

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












4















I work on a company that will not let me install any software on my computers and I run awful windows there.



I need to clean a lot of texts I copy from the intranet and save as a txt file. So I have to use sed and/or awk online live editors, like this or this



These texts are like this



01

010010-26.2010.501.0026 fafas fasdf asdf asdfsadf asdfasd fasd asasdff

fdfsadf adsf adsf asdf asdfas fadsf asdfa

02

0011-15.2016.501.0012 fafas fasdf asdf asdfsadf asdfasd fasd asasdff
asdfasd fasd asasdff
asdfasd fasd asasdff
0011-125.2013.501.0012
asdfasd fasd asasdff


See the numbers like 0011-15.2016.501.0012 this is what I want. I do not care for the rest but I want to create a new clean text with all these numbers, one per line. In the previous example, I need a text with



010010-26.2010.501.0026
0011-15.2016.501.0012
0011-125.2013.501.0012


the .501. is always present, in all numbers, as the 4th group.



I have tried this command on the sed online editor



's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*)/1/'


Not working.










share|improve this question
























  • I am using this online tool... sed.js.org this is the tool I will have to use, so the command has to work there.

    – SpaceDog
    Feb 17 at 18:42












  • I have mentioned in my question.

    – SpaceDog
    Feb 17 at 18:57











  • This is not an answer for your original question (that's already solved), but you might want to check if you can use Powershell. On newer windows machines it's installed by default (I think), so if it's on your machine, you might be able to use it. It has regular expression support, exactly what you need here. In case you're forced to use one MS product anyway, you could just go all in. ;)

    – Nyos
    Feb 17 at 20:32















4















I work on a company that will not let me install any software on my computers and I run awful windows there.



I need to clean a lot of texts I copy from the intranet and save as a txt file. So I have to use sed and/or awk online live editors, like this or this



These texts are like this



01

010010-26.2010.501.0026 fafas fasdf asdf asdfsadf asdfasd fasd asasdff

fdfsadf adsf adsf asdf asdfas fadsf asdfa

02

0011-15.2016.501.0012 fafas fasdf asdf asdfsadf asdfasd fasd asasdff
asdfasd fasd asasdff
asdfasd fasd asasdff
0011-125.2013.501.0012
asdfasd fasd asasdff


See the numbers like 0011-15.2016.501.0012 this is what I want. I do not care for the rest but I want to create a new clean text with all these numbers, one per line. In the previous example, I need a text with



010010-26.2010.501.0026
0011-15.2016.501.0012
0011-125.2013.501.0012


the .501. is always present, in all numbers, as the 4th group.



I have tried this command on the sed online editor



's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*)/1/'


Not working.










share|improve this question
























  • I am using this online tool... sed.js.org this is the tool I will have to use, so the command has to work there.

    – SpaceDog
    Feb 17 at 18:42












  • I have mentioned in my question.

    – SpaceDog
    Feb 17 at 18:57











  • This is not an answer for your original question (that's already solved), but you might want to check if you can use Powershell. On newer windows machines it's installed by default (I think), so if it's on your machine, you might be able to use it. It has regular expression support, exactly what you need here. In case you're forced to use one MS product anyway, you could just go all in. ;)

    – Nyos
    Feb 17 at 20:32













4












4








4


1






I work on a company that will not let me install any software on my computers and I run awful windows there.



I need to clean a lot of texts I copy from the intranet and save as a txt file. So I have to use sed and/or awk online live editors, like this or this



These texts are like this



01

010010-26.2010.501.0026 fafas fasdf asdf asdfsadf asdfasd fasd asasdff

fdfsadf adsf adsf asdf asdfas fadsf asdfa

02

0011-15.2016.501.0012 fafas fasdf asdf asdfsadf asdfasd fasd asasdff
asdfasd fasd asasdff
asdfasd fasd asasdff
0011-125.2013.501.0012
asdfasd fasd asasdff


See the numbers like 0011-15.2016.501.0012 this is what I want. I do not care for the rest but I want to create a new clean text with all these numbers, one per line. In the previous example, I need a text with



010010-26.2010.501.0026
0011-15.2016.501.0012
0011-125.2013.501.0012


the .501. is always present, in all numbers, as the 4th group.



I have tried this command on the sed online editor



's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*)/1/'


Not working.










share|improve this question
















I work on a company that will not let me install any software on my computers and I run awful windows there.



I need to clean a lot of texts I copy from the intranet and save as a txt file. So I have to use sed and/or awk online live editors, like this or this



These texts are like this



01

010010-26.2010.501.0026 fafas fasdf asdf asdfsadf asdfasd fasd asasdff

fdfsadf adsf adsf asdf asdfas fadsf asdfa

02

0011-15.2016.501.0012 fafas fasdf asdf asdfsadf asdfasd fasd asasdff
asdfasd fasd asasdff
asdfasd fasd asasdff
0011-125.2013.501.0012
asdfasd fasd asasdff


See the numbers like 0011-15.2016.501.0012 this is what I want. I do not care for the rest but I want to create a new clean text with all these numbers, one per line. In the previous example, I need a text with



010010-26.2010.501.0026
0011-15.2016.501.0012
0011-125.2013.501.0012


the .501. is always present, in all numbers, as the 4th group.



I have tried this command on the sed online editor



's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*)/1/'


Not working.







text-processing awk sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 17 at 18:49









jimmij

32.2k874109




32.2k874109










asked Feb 17 at 18:28









SpaceDogSpaceDog

1,767123155




1,767123155












  • I am using this online tool... sed.js.org this is the tool I will have to use, so the command has to work there.

    – SpaceDog
    Feb 17 at 18:42












  • I have mentioned in my question.

    – SpaceDog
    Feb 17 at 18:57











  • This is not an answer for your original question (that's already solved), but you might want to check if you can use Powershell. On newer windows machines it's installed by default (I think), so if it's on your machine, you might be able to use it. It has regular expression support, exactly what you need here. In case you're forced to use one MS product anyway, you could just go all in. ;)

    – Nyos
    Feb 17 at 20:32

















  • I am using this online tool... sed.js.org this is the tool I will have to use, so the command has to work there.

    – SpaceDog
    Feb 17 at 18:42












  • I have mentioned in my question.

    – SpaceDog
    Feb 17 at 18:57











  • This is not an answer for your original question (that's already solved), but you might want to check if you can use Powershell. On newer windows machines it's installed by default (I think), so if it's on your machine, you might be able to use it. It has regular expression support, exactly what you need here. In case you're forced to use one MS product anyway, you could just go all in. ;)

    – Nyos
    Feb 17 at 20:32
















I am using this online tool... sed.js.org this is the tool I will have to use, so the command has to work there.

– SpaceDog
Feb 17 at 18:42






I am using this online tool... sed.js.org this is the tool I will have to use, so the command has to work there.

– SpaceDog
Feb 17 at 18:42














I have mentioned in my question.

– SpaceDog
Feb 17 at 18:57





I have mentioned in my question.

– SpaceDog
Feb 17 at 18:57













This is not an answer for your original question (that's already solved), but you might want to check if you can use Powershell. On newer windows machines it's installed by default (I think), so if it's on your machine, you might be able to use it. It has regular expression support, exactly what you need here. In case you're forced to use one MS product anyway, you could just go all in. ;)

– Nyos
Feb 17 at 20:32





This is not an answer for your original question (that's already solved), but you might want to check if you can use Powershell. On newer windows machines it's installed by default (I think), so if it's on your machine, you might be able to use it. It has regular expression support, exactly what you need here. In case you're forced to use one MS product anyway, you could just go all in. ;)

– Nyos
Feb 17 at 20:32










2 Answers
2






active

oldest

votes


















7














It does work, but you don't change anything, or rather change it to what it was. But with very small modification of this code you can get what you want:



sed -n 's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*).*/1/p'


Notice three things:




  • -n switch, it means to not print anything by default


  • .* at the end of the group selected with (...)


  • p as a last command means print this line

Result:



010010-26.2010.501.0026
0011-15.2016.501.0012
0011-125.2013.501.0012


BTW, you can simplify a little by adding -E and using extended regular expression, i.e. get rid of backslashes in front of capturing groups:



sed -E -n 's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*).*/1/p'


Both ways work on mentioned webpage.






share|improve this answer

























  • yeah, i hate this. you post your answer 12 seconds LATER and get all the credit. i will take this to meta one day ...

    – Bananguin
    Feb 17 at 18:58











  • @Bananguin Yeah, I see, perhaps because of not corrected (imho) statement about escaping -? But I've just upvoted your question as it is very good in most part.

    – jimmij
    Feb 17 at 19:03












  • thanks :D. In your oppinion not correct? But you still modified your answer and removed the escaping ``. The hyphen is no special character. Why would it need escaping? I didn't care much for the web-implementation, I just guessed that it might have tripped over that, if the statement was "not working". Turns out on my commandline I can "escape" the hyphen. So it's more a stuff character than an escape sequence. Why not ... I guess.

    – Bananguin
    Feb 17 at 19:11











  • I would ask about escaping the - but it is working without the escape. So, thanks.

    – SpaceDog
    Feb 17 at 19:12






  • 1





    @Bananguin Backslash in front of a - is not necessary, but at the same time doesn't do any harm. It only says to treat character that follows literally, but - is treated like that anyway (in this context). So in my "minimal" modified example I left it, but when it comes to simplification I removed it together with other backslashes. It is working either way.

    – jimmij
    Feb 17 at 19:18



















7














It is fairly straight forward with AWK, b/c usually AWK doesn't do anything, so we just need to tell it when to do things, i.e. print the ID at the beginning of the line, if it's there



/^[0-9]+-[0-9]+.[0-9]+.501.[0-9]+/
print $1



With sed it's a little different, b/c by default sed will print everything. (At least that's how these tools have been working for me.) First, we need to invoke sed as sed -n, to change its default behaviour to not do anything. Then we can



s/^([0-9]+-[0-9]+.[0-9]+.501.[0-9]+).*$/1/p


We need the p at the end to tell sed to print the result, if we had a matching pattern. Your particular sed expression is a NOOP because it replaces every match with itself and prints everything else as it was.






share|improve this answer

























  • thanks for your answer!!!

    – SpaceDog
    Feb 17 at 22:24










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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
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%2f501213%2fhow-to-remove-specific-numbers-from-a-txt-file-with-sed-or-awk%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














It does work, but you don't change anything, or rather change it to what it was. But with very small modification of this code you can get what you want:



sed -n 's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*).*/1/p'


Notice three things:




  • -n switch, it means to not print anything by default


  • .* at the end of the group selected with (...)


  • p as a last command means print this line

Result:



010010-26.2010.501.0026
0011-15.2016.501.0012
0011-125.2013.501.0012


BTW, you can simplify a little by adding -E and using extended regular expression, i.e. get rid of backslashes in front of capturing groups:



sed -E -n 's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*).*/1/p'


Both ways work on mentioned webpage.






share|improve this answer

























  • yeah, i hate this. you post your answer 12 seconds LATER and get all the credit. i will take this to meta one day ...

    – Bananguin
    Feb 17 at 18:58











  • @Bananguin Yeah, I see, perhaps because of not corrected (imho) statement about escaping -? But I've just upvoted your question as it is very good in most part.

    – jimmij
    Feb 17 at 19:03












  • thanks :D. In your oppinion not correct? But you still modified your answer and removed the escaping ``. The hyphen is no special character. Why would it need escaping? I didn't care much for the web-implementation, I just guessed that it might have tripped over that, if the statement was "not working". Turns out on my commandline I can "escape" the hyphen. So it's more a stuff character than an escape sequence. Why not ... I guess.

    – Bananguin
    Feb 17 at 19:11











  • I would ask about escaping the - but it is working without the escape. So, thanks.

    – SpaceDog
    Feb 17 at 19:12






  • 1





    @Bananguin Backslash in front of a - is not necessary, but at the same time doesn't do any harm. It only says to treat character that follows literally, but - is treated like that anyway (in this context). So in my "minimal" modified example I left it, but when it comes to simplification I removed it together with other backslashes. It is working either way.

    – jimmij
    Feb 17 at 19:18
















7














It does work, but you don't change anything, or rather change it to what it was. But with very small modification of this code you can get what you want:



sed -n 's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*).*/1/p'


Notice three things:




  • -n switch, it means to not print anything by default


  • .* at the end of the group selected with (...)


  • p as a last command means print this line

Result:



010010-26.2010.501.0026
0011-15.2016.501.0012
0011-125.2013.501.0012


BTW, you can simplify a little by adding -E and using extended regular expression, i.e. get rid of backslashes in front of capturing groups:



sed -E -n 's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*).*/1/p'


Both ways work on mentioned webpage.






share|improve this answer

























  • yeah, i hate this. you post your answer 12 seconds LATER and get all the credit. i will take this to meta one day ...

    – Bananguin
    Feb 17 at 18:58











  • @Bananguin Yeah, I see, perhaps because of not corrected (imho) statement about escaping -? But I've just upvoted your question as it is very good in most part.

    – jimmij
    Feb 17 at 19:03












  • thanks :D. In your oppinion not correct? But you still modified your answer and removed the escaping ``. The hyphen is no special character. Why would it need escaping? I didn't care much for the web-implementation, I just guessed that it might have tripped over that, if the statement was "not working". Turns out on my commandline I can "escape" the hyphen. So it's more a stuff character than an escape sequence. Why not ... I guess.

    – Bananguin
    Feb 17 at 19:11











  • I would ask about escaping the - but it is working without the escape. So, thanks.

    – SpaceDog
    Feb 17 at 19:12






  • 1





    @Bananguin Backslash in front of a - is not necessary, but at the same time doesn't do any harm. It only says to treat character that follows literally, but - is treated like that anyway (in this context). So in my "minimal" modified example I left it, but when it comes to simplification I removed it together with other backslashes. It is working either way.

    – jimmij
    Feb 17 at 19:18














7












7








7







It does work, but you don't change anything, or rather change it to what it was. But with very small modification of this code you can get what you want:



sed -n 's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*).*/1/p'


Notice three things:




  • -n switch, it means to not print anything by default


  • .* at the end of the group selected with (...)


  • p as a last command means print this line

Result:



010010-26.2010.501.0026
0011-15.2016.501.0012
0011-125.2013.501.0012


BTW, you can simplify a little by adding -E and using extended regular expression, i.e. get rid of backslashes in front of capturing groups:



sed -E -n 's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*).*/1/p'


Both ways work on mentioned webpage.






share|improve this answer















It does work, but you don't change anything, or rather change it to what it was. But with very small modification of this code you can get what you want:



sed -n 's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*).*/1/p'


Notice three things:




  • -n switch, it means to not print anything by default


  • .* at the end of the group selected with (...)


  • p as a last command means print this line

Result:



010010-26.2010.501.0026
0011-15.2016.501.0012
0011-125.2013.501.0012


BTW, you can simplify a little by adding -E and using extended regular expression, i.e. get rid of backslashes in front of capturing groups:



sed -E -n 's/([0-9]*-[0-9]*.[0-9]*.501.[0-9]*).*/1/p'


Both ways work on mentioned webpage.







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 17 at 18:57

























answered Feb 17 at 18:46









jimmijjimmij

32.2k874109




32.2k874109












  • yeah, i hate this. you post your answer 12 seconds LATER and get all the credit. i will take this to meta one day ...

    – Bananguin
    Feb 17 at 18:58











  • @Bananguin Yeah, I see, perhaps because of not corrected (imho) statement about escaping -? But I've just upvoted your question as it is very good in most part.

    – jimmij
    Feb 17 at 19:03












  • thanks :D. In your oppinion not correct? But you still modified your answer and removed the escaping ``. The hyphen is no special character. Why would it need escaping? I didn't care much for the web-implementation, I just guessed that it might have tripped over that, if the statement was "not working". Turns out on my commandline I can "escape" the hyphen. So it's more a stuff character than an escape sequence. Why not ... I guess.

    – Bananguin
    Feb 17 at 19:11











  • I would ask about escaping the - but it is working without the escape. So, thanks.

    – SpaceDog
    Feb 17 at 19:12






  • 1





    @Bananguin Backslash in front of a - is not necessary, but at the same time doesn't do any harm. It only says to treat character that follows literally, but - is treated like that anyway (in this context). So in my "minimal" modified example I left it, but when it comes to simplification I removed it together with other backslashes. It is working either way.

    – jimmij
    Feb 17 at 19:18


















  • yeah, i hate this. you post your answer 12 seconds LATER and get all the credit. i will take this to meta one day ...

    – Bananguin
    Feb 17 at 18:58











  • @Bananguin Yeah, I see, perhaps because of not corrected (imho) statement about escaping -? But I've just upvoted your question as it is very good in most part.

    – jimmij
    Feb 17 at 19:03












  • thanks :D. In your oppinion not correct? But you still modified your answer and removed the escaping ``. The hyphen is no special character. Why would it need escaping? I didn't care much for the web-implementation, I just guessed that it might have tripped over that, if the statement was "not working". Turns out on my commandline I can "escape" the hyphen. So it's more a stuff character than an escape sequence. Why not ... I guess.

    – Bananguin
    Feb 17 at 19:11











  • I would ask about escaping the - but it is working without the escape. So, thanks.

    – SpaceDog
    Feb 17 at 19:12






  • 1





    @Bananguin Backslash in front of a - is not necessary, but at the same time doesn't do any harm. It only says to treat character that follows literally, but - is treated like that anyway (in this context). So in my "minimal" modified example I left it, but when it comes to simplification I removed it together with other backslashes. It is working either way.

    – jimmij
    Feb 17 at 19:18

















yeah, i hate this. you post your answer 12 seconds LATER and get all the credit. i will take this to meta one day ...

– Bananguin
Feb 17 at 18:58





yeah, i hate this. you post your answer 12 seconds LATER and get all the credit. i will take this to meta one day ...

– Bananguin
Feb 17 at 18:58













@Bananguin Yeah, I see, perhaps because of not corrected (imho) statement about escaping -? But I've just upvoted your question as it is very good in most part.

– jimmij
Feb 17 at 19:03






@Bananguin Yeah, I see, perhaps because of not corrected (imho) statement about escaping -? But I've just upvoted your question as it is very good in most part.

– jimmij
Feb 17 at 19:03














thanks :D. In your oppinion not correct? But you still modified your answer and removed the escaping ``. The hyphen is no special character. Why would it need escaping? I didn't care much for the web-implementation, I just guessed that it might have tripped over that, if the statement was "not working". Turns out on my commandline I can "escape" the hyphen. So it's more a stuff character than an escape sequence. Why not ... I guess.

– Bananguin
Feb 17 at 19:11





thanks :D. In your oppinion not correct? But you still modified your answer and removed the escaping ``. The hyphen is no special character. Why would it need escaping? I didn't care much for the web-implementation, I just guessed that it might have tripped over that, if the statement was "not working". Turns out on my commandline I can "escape" the hyphen. So it's more a stuff character than an escape sequence. Why not ... I guess.

– Bananguin
Feb 17 at 19:11













I would ask about escaping the - but it is working without the escape. So, thanks.

– SpaceDog
Feb 17 at 19:12





I would ask about escaping the - but it is working without the escape. So, thanks.

– SpaceDog
Feb 17 at 19:12




1




1





@Bananguin Backslash in front of a - is not necessary, but at the same time doesn't do any harm. It only says to treat character that follows literally, but - is treated like that anyway (in this context). So in my "minimal" modified example I left it, but when it comes to simplification I removed it together with other backslashes. It is working either way.

– jimmij
Feb 17 at 19:18






@Bananguin Backslash in front of a - is not necessary, but at the same time doesn't do any harm. It only says to treat character that follows literally, but - is treated like that anyway (in this context). So in my "minimal" modified example I left it, but when it comes to simplification I removed it together with other backslashes. It is working either way.

– jimmij
Feb 17 at 19:18














7














It is fairly straight forward with AWK, b/c usually AWK doesn't do anything, so we just need to tell it when to do things, i.e. print the ID at the beginning of the line, if it's there



/^[0-9]+-[0-9]+.[0-9]+.501.[0-9]+/
print $1



With sed it's a little different, b/c by default sed will print everything. (At least that's how these tools have been working for me.) First, we need to invoke sed as sed -n, to change its default behaviour to not do anything. Then we can



s/^([0-9]+-[0-9]+.[0-9]+.501.[0-9]+).*$/1/p


We need the p at the end to tell sed to print the result, if we had a matching pattern. Your particular sed expression is a NOOP because it replaces every match with itself and prints everything else as it was.






share|improve this answer

























  • thanks for your answer!!!

    – SpaceDog
    Feb 17 at 22:24















7














It is fairly straight forward with AWK, b/c usually AWK doesn't do anything, so we just need to tell it when to do things, i.e. print the ID at the beginning of the line, if it's there



/^[0-9]+-[0-9]+.[0-9]+.501.[0-9]+/
print $1



With sed it's a little different, b/c by default sed will print everything. (At least that's how these tools have been working for me.) First, we need to invoke sed as sed -n, to change its default behaviour to not do anything. Then we can



s/^([0-9]+-[0-9]+.[0-9]+.501.[0-9]+).*$/1/p


We need the p at the end to tell sed to print the result, if we had a matching pattern. Your particular sed expression is a NOOP because it replaces every match with itself and prints everything else as it was.






share|improve this answer

























  • thanks for your answer!!!

    – SpaceDog
    Feb 17 at 22:24













7












7








7







It is fairly straight forward with AWK, b/c usually AWK doesn't do anything, so we just need to tell it when to do things, i.e. print the ID at the beginning of the line, if it's there



/^[0-9]+-[0-9]+.[0-9]+.501.[0-9]+/
print $1



With sed it's a little different, b/c by default sed will print everything. (At least that's how these tools have been working for me.) First, we need to invoke sed as sed -n, to change its default behaviour to not do anything. Then we can



s/^([0-9]+-[0-9]+.[0-9]+.501.[0-9]+).*$/1/p


We need the p at the end to tell sed to print the result, if we had a matching pattern. Your particular sed expression is a NOOP because it replaces every match with itself and prints everything else as it was.






share|improve this answer















It is fairly straight forward with AWK, b/c usually AWK doesn't do anything, so we just need to tell it when to do things, i.e. print the ID at the beginning of the line, if it's there



/^[0-9]+-[0-9]+.[0-9]+.501.[0-9]+/
print $1



With sed it's a little different, b/c by default sed will print everything. (At least that's how these tools have been working for me.) First, we need to invoke sed as sed -n, to change its default behaviour to not do anything. Then we can



s/^([0-9]+-[0-9]+.[0-9]+.501.[0-9]+).*$/1/p


We need the p at the end to tell sed to print the result, if we had a matching pattern. Your particular sed expression is a NOOP because it replaces every match with itself and prints everything else as it was.







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 17 at 22:25

























answered Feb 17 at 18:46









BananguinBananguin

5,4151340




5,4151340












  • thanks for your answer!!!

    – SpaceDog
    Feb 17 at 22:24

















  • thanks for your answer!!!

    – SpaceDog
    Feb 17 at 22:24
















thanks for your answer!!!

– SpaceDog
Feb 17 at 22:24





thanks for your answer!!!

– SpaceDog
Feb 17 at 22:24

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f501213%2fhow-to-remove-specific-numbers-from-a-txt-file-with-sed-or-awk%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

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

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay