Fetch line which contains only some specific symbol and number

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












-2















I Need only those records from below file which contains Symbol like "+" and number and characters.



285627
AA283244
278178##
295456+
asdfasdf{
asdfasdfasdf


I tried below code but it gives all records



grep -E '[a-zA-Z0-9]+' temp.txt 


I need only those records which contains either letters or number or + sign. If any record contains any other characters then it should be discarded. Record number 3 and 5 should not come in result:



285627
AA283244
295456+
asdfasdfasdf









share|improve this question



















  • 1





    Welcome to the U&L SE. There's only one entry in your question that has a the '+' character in it. Is that the only type of pattern (6 digits followed by a '+') or do you have other patterns you want to look for?

    – Haxiel
    Jan 16 at 16:04











  • I Need only those records which contains either letters or Number or + sign. If any record contains any other characters then it should be discarded.

    – user331805
    Jan 16 at 16:06






  • 1





    Every line there contains "characters "; which ones exactly do you want to include or exclude?

    – Jeff Schaller
    Jan 16 at 16:06











  • Rather than provide relevant details in comments, you should edit the question to improve its quality. I came across this question because it had been nominated for closure due to its lack of clarity. I voted to keep it open and edited it for you -- but you should really do this yourself. See How to Ask.

    – Anthony Geoghegan
    Jan 16 at 19:17















-2















I Need only those records from below file which contains Symbol like "+" and number and characters.



285627
AA283244
278178##
295456+
asdfasdf{
asdfasdfasdf


I tried below code but it gives all records



grep -E '[a-zA-Z0-9]+' temp.txt 


I need only those records which contains either letters or number or + sign. If any record contains any other characters then it should be discarded. Record number 3 and 5 should not come in result:



285627
AA283244
295456+
asdfasdfasdf









share|improve this question



















  • 1





    Welcome to the U&L SE. There's only one entry in your question that has a the '+' character in it. Is that the only type of pattern (6 digits followed by a '+') or do you have other patterns you want to look for?

    – Haxiel
    Jan 16 at 16:04











  • I Need only those records which contains either letters or Number or + sign. If any record contains any other characters then it should be discarded.

    – user331805
    Jan 16 at 16:06






  • 1





    Every line there contains "characters "; which ones exactly do you want to include or exclude?

    – Jeff Schaller
    Jan 16 at 16:06











  • Rather than provide relevant details in comments, you should edit the question to improve its quality. I came across this question because it had been nominated for closure due to its lack of clarity. I voted to keep it open and edited it for you -- but you should really do this yourself. See How to Ask.

    – Anthony Geoghegan
    Jan 16 at 19:17













-2












-2








-2








I Need only those records from below file which contains Symbol like "+" and number and characters.



285627
AA283244
278178##
295456+
asdfasdf{
asdfasdfasdf


I tried below code but it gives all records



grep -E '[a-zA-Z0-9]+' temp.txt 


I need only those records which contains either letters or number or + sign. If any record contains any other characters then it should be discarded. Record number 3 and 5 should not come in result:



285627
AA283244
295456+
asdfasdfasdf









share|improve this question
















I Need only those records from below file which contains Symbol like "+" and number and characters.



285627
AA283244
278178##
295456+
asdfasdf{
asdfasdfasdf


I tried below code but it gives all records



grep -E '[a-zA-Z0-9]+' temp.txt 


I need only those records which contains either letters or number or + sign. If any record contains any other characters then it should be discarded. Record number 3 and 5 should not come in result:



285627
AA283244
295456+
asdfasdfasdf






text-processing grep






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 16 at 19:15









Anthony Geoghegan

7,73443954




7,73443954










asked Jan 16 at 15:41









user331805user331805

11




11







  • 1





    Welcome to the U&L SE. There's only one entry in your question that has a the '+' character in it. Is that the only type of pattern (6 digits followed by a '+') or do you have other patterns you want to look for?

    – Haxiel
    Jan 16 at 16:04











  • I Need only those records which contains either letters or Number or + sign. If any record contains any other characters then it should be discarded.

    – user331805
    Jan 16 at 16:06






  • 1





    Every line there contains "characters "; which ones exactly do you want to include or exclude?

    – Jeff Schaller
    Jan 16 at 16:06











  • Rather than provide relevant details in comments, you should edit the question to improve its quality. I came across this question because it had been nominated for closure due to its lack of clarity. I voted to keep it open and edited it for you -- but you should really do this yourself. See How to Ask.

    – Anthony Geoghegan
    Jan 16 at 19:17












  • 1





    Welcome to the U&L SE. There's only one entry in your question that has a the '+' character in it. Is that the only type of pattern (6 digits followed by a '+') or do you have other patterns you want to look for?

    – Haxiel
    Jan 16 at 16:04











  • I Need only those records which contains either letters or Number or + sign. If any record contains any other characters then it should be discarded.

    – user331805
    Jan 16 at 16:06






  • 1





    Every line there contains "characters "; which ones exactly do you want to include or exclude?

    – Jeff Schaller
    Jan 16 at 16:06











  • Rather than provide relevant details in comments, you should edit the question to improve its quality. I came across this question because it had been nominated for closure due to its lack of clarity. I voted to keep it open and edited it for you -- but you should really do this yourself. See How to Ask.

    – Anthony Geoghegan
    Jan 16 at 19:17







1




1





Welcome to the U&L SE. There's only one entry in your question that has a the '+' character in it. Is that the only type of pattern (6 digits followed by a '+') or do you have other patterns you want to look for?

– Haxiel
Jan 16 at 16:04





Welcome to the U&L SE. There's only one entry in your question that has a the '+' character in it. Is that the only type of pattern (6 digits followed by a '+') or do you have other patterns you want to look for?

– Haxiel
Jan 16 at 16:04













I Need only those records which contains either letters or Number or + sign. If any record contains any other characters then it should be discarded.

– user331805
Jan 16 at 16:06





I Need only those records which contains either letters or Number or + sign. If any record contains any other characters then it should be discarded.

– user331805
Jan 16 at 16:06




1




1





Every line there contains "characters "; which ones exactly do you want to include or exclude?

– Jeff Schaller
Jan 16 at 16:06





Every line there contains "characters "; which ones exactly do you want to include or exclude?

– Jeff Schaller
Jan 16 at 16:06













Rather than provide relevant details in comments, you should edit the question to improve its quality. I came across this question because it had been nominated for closure due to its lack of clarity. I voted to keep it open and edited it for you -- but you should really do this yourself. See How to Ask.

– Anthony Geoghegan
Jan 16 at 19:17





Rather than provide relevant details in comments, you should edit the question to improve its quality. I came across this question because it had been nominated for closure due to its lack of clarity. I voted to keep it open and edited it for you -- but you should really do this yourself. See How to Ask.

– Anthony Geoghegan
Jan 16 at 19:17










2 Answers
2






active

oldest

votes


















4














Remove any line that contains a character that is not (a letter or number or +):



grep -v '[^[:alnum:]+]' file





share|improve this answer






























    3














    You're missing the + in your character list. The plus after the [...] is the quantifier (1 or more of the before mentioned character group).



    Also you must enclose it in ^ for start of line and $ for end of line, as otherwise you will also match parts of each line, e.g. 278178 from 278178##.



    Try this,



    grep -E '^[a-zA-Z0-9+]+$' temp.txt 





    share|improve this answer




















    • 1





      You could add -i and simplify your pattern a bit.

      – glenn jackman
      Jan 16 at 16:46











    • Sure the pattern is not very good. My intend was to fix OPs pattern and not to provide the best one. You made it with your answer anyways ;-)

      – RoVo
      Jan 16 at 16:49











    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%2f494858%2ffetch-line-which-contains-only-some-specific-symbol-and-number%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









    4














    Remove any line that contains a character that is not (a letter or number or +):



    grep -v '[^[:alnum:]+]' file





    share|improve this answer



























      4














      Remove any line that contains a character that is not (a letter or number or +):



      grep -v '[^[:alnum:]+]' file





      share|improve this answer

























        4












        4








        4







        Remove any line that contains a character that is not (a letter or number or +):



        grep -v '[^[:alnum:]+]' file





        share|improve this answer













        Remove any line that contains a character that is not (a letter or number or +):



        grep -v '[^[:alnum:]+]' file






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 16 at 16:33









        glenn jackmanglenn jackman

        51.3k571111




        51.3k571111























            3














            You're missing the + in your character list. The plus after the [...] is the quantifier (1 or more of the before mentioned character group).



            Also you must enclose it in ^ for start of line and $ for end of line, as otherwise you will also match parts of each line, e.g. 278178 from 278178##.



            Try this,



            grep -E '^[a-zA-Z0-9+]+$' temp.txt 





            share|improve this answer




















            • 1





              You could add -i and simplify your pattern a bit.

              – glenn jackman
              Jan 16 at 16:46











            • Sure the pattern is not very good. My intend was to fix OPs pattern and not to provide the best one. You made it with your answer anyways ;-)

              – RoVo
              Jan 16 at 16:49
















            3














            You're missing the + in your character list. The plus after the [...] is the quantifier (1 or more of the before mentioned character group).



            Also you must enclose it in ^ for start of line and $ for end of line, as otherwise you will also match parts of each line, e.g. 278178 from 278178##.



            Try this,



            grep -E '^[a-zA-Z0-9+]+$' temp.txt 





            share|improve this answer




















            • 1





              You could add -i and simplify your pattern a bit.

              – glenn jackman
              Jan 16 at 16:46











            • Sure the pattern is not very good. My intend was to fix OPs pattern and not to provide the best one. You made it with your answer anyways ;-)

              – RoVo
              Jan 16 at 16:49














            3












            3








            3







            You're missing the + in your character list. The plus after the [...] is the quantifier (1 or more of the before mentioned character group).



            Also you must enclose it in ^ for start of line and $ for end of line, as otherwise you will also match parts of each line, e.g. 278178 from 278178##.



            Try this,



            grep -E '^[a-zA-Z0-9+]+$' temp.txt 





            share|improve this answer















            You're missing the + in your character list. The plus after the [...] is the quantifier (1 or more of the before mentioned character group).



            Also you must enclose it in ^ for start of line and $ for end of line, as otherwise you will also match parts of each line, e.g. 278178 from 278178##.



            Try this,



            grep -E '^[a-zA-Z0-9+]+$' temp.txt 






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 16 at 16:12

























            answered Jan 16 at 16:07









            RoVoRoVo

            3,141216




            3,141216







            • 1





              You could add -i and simplify your pattern a bit.

              – glenn jackman
              Jan 16 at 16:46











            • Sure the pattern is not very good. My intend was to fix OPs pattern and not to provide the best one. You made it with your answer anyways ;-)

              – RoVo
              Jan 16 at 16:49













            • 1





              You could add -i and simplify your pattern a bit.

              – glenn jackman
              Jan 16 at 16:46











            • Sure the pattern is not very good. My intend was to fix OPs pattern and not to provide the best one. You made it with your answer anyways ;-)

              – RoVo
              Jan 16 at 16:49








            1




            1





            You could add -i and simplify your pattern a bit.

            – glenn jackman
            Jan 16 at 16:46





            You could add -i and simplify your pattern a bit.

            – glenn jackman
            Jan 16 at 16:46













            Sure the pattern is not very good. My intend was to fix OPs pattern and not to provide the best one. You made it with your answer anyways ;-)

            – RoVo
            Jan 16 at 16:49






            Sure the pattern is not very good. My intend was to fix OPs pattern and not to provide the best one. You made it with your answer anyways ;-)

            – RoVo
            Jan 16 at 16:49


















            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%2f494858%2ffetch-line-which-contains-only-some-specific-symbol-and-number%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

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)