How to print the line from a file that contains the matching characters in the pattern

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











up vote
1
down vote

favorite












I am trying to print all the lines from a file that has the same characters of the matching pattern.
Here is my pattern -



CurrentPrincipal[MRC]
CurrentPrincipalLegalEventAssociation


In the file I have the lines like the below ones



823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition


I am iterating my pattern and printing its matching lines from the file. What I need is, when I iterate my pattern CurrentPrincipal[MRC] I should get only its matching line



d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition



and when the pattern is CurrentPrincipalLegalEventAssociation I should get only



c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition



My requirement is to ignore the [ ] from the line while matching pattern.
I have tried my best to put my issue affront. Do let me know if anything else is needed from me.
Thanks in advance.







share|improve this question
















  • 1




    I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
    – terdon♦
    Jan 5 at 12:16














up vote
1
down vote

favorite












I am trying to print all the lines from a file that has the same characters of the matching pattern.
Here is my pattern -



CurrentPrincipal[MRC]
CurrentPrincipalLegalEventAssociation


In the file I have the lines like the below ones



823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition


I am iterating my pattern and printing its matching lines from the file. What I need is, when I iterate my pattern CurrentPrincipal[MRC] I should get only its matching line



d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition



and when the pattern is CurrentPrincipalLegalEventAssociation I should get only



c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition



My requirement is to ignore the [ ] from the line while matching pattern.
I have tried my best to put my issue affront. Do let me know if anything else is needed from me.
Thanks in advance.







share|improve this question
















  • 1




    I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
    – terdon♦
    Jan 5 at 12:16












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to print all the lines from a file that has the same characters of the matching pattern.
Here is my pattern -



CurrentPrincipal[MRC]
CurrentPrincipalLegalEventAssociation


In the file I have the lines like the below ones



823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition


I am iterating my pattern and printing its matching lines from the file. What I need is, when I iterate my pattern CurrentPrincipal[MRC] I should get only its matching line



d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition



and when the pattern is CurrentPrincipalLegalEventAssociation I should get only



c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition



My requirement is to ignore the [ ] from the line while matching pattern.
I have tried my best to put my issue affront. Do let me know if anything else is needed from me.
Thanks in advance.







share|improve this question












I am trying to print all the lines from a file that has the same characters of the matching pattern.
Here is my pattern -



CurrentPrincipal[MRC]
CurrentPrincipalLegalEventAssociation


In the file I have the lines like the below ones



823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition


I am iterating my pattern and printing its matching lines from the file. What I need is, when I iterate my pattern CurrentPrincipal[MRC] I should get only its matching line



d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition



and when the pattern is CurrentPrincipalLegalEventAssociation I should get only



c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition



My requirement is to ignore the [ ] from the line while matching pattern.
I have tried my best to put my issue affront. Do let me know if anything else is needed from me.
Thanks in advance.









share|improve this question











share|improve this question




share|improve this question










asked Jan 4 at 14:06









Alex Raj Kaliamoorthy

192111




192111







  • 1




    I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
    – terdon♦
    Jan 5 at 12:16












  • 1




    I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
    – terdon♦
    Jan 5 at 12:16







1




1




I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
– terdon♦
Jan 5 at 12:16




I'm sorry but I don't understand what you need. Please edit your question and show us an example of your input file, including both desired and undesired lines, and then show us the output you would expect from that example.
– terdon♦
Jan 5 at 12:16










3 Answers
3






active

oldest

votes

















up vote
2
down vote













You appear to want the [ and ] characters to be treated literally rather than as indicating a character range. You can do that by escaping them:



grep 'CurrentPrincipal[LegalEventAssociation]' file


Ex. given:



$ cat file
823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition


then



$ grep 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition


Alternatively use the -F or --fixed-strings option to tell grep to treat all characters literally:



$ grep -F 'CurrentPrincipal[LegalEventAssociation]' file
c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition





share|improve this answer






















  • This is fine but my search pattern is CurrentPrincipalLegalEventAssociation and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the line c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Typ‌​e][*],CompanyElement‌ when the search pattern is CurrentPrincipalLegalEventAssociation. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
    – Alex Raj Kaliamoorthy
    Jan 4 at 14:19






  • 1




    @AlexRajKaliamoorthy please see my updated answer using grep -F. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower case f) to read patterns directly from a file.
    – steeldriver
    Jan 4 at 14:27











  • Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is just CurrentPrincipalLegalEventAssociation
    – Alex Raj Kaliamoorthy
    Jan 4 at 14:35






  • 1




    @AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
    – Jesse_b
    Jan 4 at 15:10







  • 1




    Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
    – Jesse_b
    Jan 4 at 15:16

















up vote
1
down vote













grep seems to do what you want.



grep 'word' filename


Will print every line in the file 'filename' that contains 'word'.






share|improve this answer




















  • I have tried this already but if you see, my file has 1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition and I need only c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition . The line I need contains brackets and I want to ignore that while searching.
    – Alex Raj Kaliamoorthy
    Jan 4 at 14:13


















up vote
0
down vote













Using the following, the file output appears in next line in the file after pattern search line.



sed -n '/CurrentPrincipal[MRC]/p' filename | sed -n '2p' 


Output



d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition 



sed -n '/CurrentPrincipalLegalEventAssociation/,+1p' l.txt | sed -n '2p'


Output



c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition





share|improve this answer






















    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%2f414774%2fhow-to-print-the-line-from-a-file-that-contains-the-matching-characters-in-the-p%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    You appear to want the [ and ] characters to be treated literally rather than as indicating a character range. You can do that by escaping them:



    grep 'CurrentPrincipal[LegalEventAssociation]' file


    Ex. given:



    $ cat file
    823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
    d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
    1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
    8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition


    then



    $ grep 'CurrentPrincipal[LegalEventAssociation]' file
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition


    Alternatively use the -F or --fixed-strings option to tell grep to treat all characters literally:



    $ grep -F 'CurrentPrincipal[LegalEventAssociation]' file
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition





    share|improve this answer






















    • This is fine but my search pattern is CurrentPrincipalLegalEventAssociation and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the line c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Typ‌​e][*],CompanyElement‌ when the search pattern is CurrentPrincipalLegalEventAssociation. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:19






    • 1




      @AlexRajKaliamoorthy please see my updated answer using grep -F. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower case f) to read patterns directly from a file.
      – steeldriver
      Jan 4 at 14:27











    • Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is just CurrentPrincipalLegalEventAssociation
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:35






    • 1




      @AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
      – Jesse_b
      Jan 4 at 15:10







    • 1




      Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
      – Jesse_b
      Jan 4 at 15:16














    up vote
    2
    down vote













    You appear to want the [ and ] characters to be treated literally rather than as indicating a character range. You can do that by escaping them:



    grep 'CurrentPrincipal[LegalEventAssociation]' file


    Ex. given:



    $ cat file
    823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
    d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
    1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
    8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition


    then



    $ grep 'CurrentPrincipal[LegalEventAssociation]' file
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition


    Alternatively use the -F or --fixed-strings option to tell grep to treat all characters literally:



    $ grep -F 'CurrentPrincipal[LegalEventAssociation]' file
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition





    share|improve this answer






















    • This is fine but my search pattern is CurrentPrincipalLegalEventAssociation and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the line c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Typ‌​e][*],CompanyElement‌ when the search pattern is CurrentPrincipalLegalEventAssociation. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:19






    • 1




      @AlexRajKaliamoorthy please see my updated answer using grep -F. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower case f) to read patterns directly from a file.
      – steeldriver
      Jan 4 at 14:27











    • Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is just CurrentPrincipalLegalEventAssociation
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:35






    • 1




      @AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
      – Jesse_b
      Jan 4 at 15:10







    • 1




      Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
      – Jesse_b
      Jan 4 at 15:16












    up vote
    2
    down vote










    up vote
    2
    down vote









    You appear to want the [ and ] characters to be treated literally rather than as indicating a character range. You can do that by escaping them:



    grep 'CurrentPrincipal[LegalEventAssociation]' file


    Ex. given:



    $ cat file
    823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
    d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
    1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
    8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition


    then



    $ grep 'CurrentPrincipal[LegalEventAssociation]' file
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition


    Alternatively use the -F or --fixed-strings option to tell grep to treat all characters literally:



    $ grep -F 'CurrentPrincipal[LegalEventAssociation]' file
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition





    share|improve this answer














    You appear to want the [ and ] characters to be treated literally rather than as indicating a character range. You can do that by escaping them:



    grep 'CurrentPrincipal[LegalEventAssociation]' file


    Ex. given:



    $ cat file
    823,agg.listgroup,CurrentPrincipal[MRC],CompanyElementDefinition
    d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition
    1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition
    8798c3,atom.list,CurrentPrincipal[MailingAddressStreetLine1][*],CompanyElementDefinition


    then



    $ grep 'CurrentPrincipal[LegalEventAssociation]' file
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition


    Alternatively use the -F or --fixed-strings option to tell grep to treat all characters literally:



    $ grep -F 'CurrentPrincipal[LegalEventAssociation]' file
    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 4 at 14:26

























    answered Jan 4 at 14:15









    steeldriver

    31.6k34979




    31.6k34979











    • This is fine but my search pattern is CurrentPrincipalLegalEventAssociation and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the line c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Typ‌​e][*],CompanyElement‌ when the search pattern is CurrentPrincipalLegalEventAssociation. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:19






    • 1




      @AlexRajKaliamoorthy please see my updated answer using grep -F. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower case f) to read patterns directly from a file.
      – steeldriver
      Jan 4 at 14:27











    • Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is just CurrentPrincipalLegalEventAssociation
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:35






    • 1




      @AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
      – Jesse_b
      Jan 4 at 15:10







    • 1




      Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
      – Jesse_b
      Jan 4 at 15:16
















    • This is fine but my search pattern is CurrentPrincipalLegalEventAssociation and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the line c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Typ‌​e][*],CompanyElement‌ when the search pattern is CurrentPrincipalLegalEventAssociation. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:19






    • 1




      @AlexRajKaliamoorthy please see my updated answer using grep -F. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower case f) to read patterns directly from a file.
      – steeldriver
      Jan 4 at 14:27











    • Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is just CurrentPrincipalLegalEventAssociation
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:35






    • 1




      @AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
      – Jesse_b
      Jan 4 at 15:10







    • 1




      Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
      – Jesse_b
      Jan 4 at 15:16















    This is fine but my search pattern is CurrentPrincipalLegalEventAssociation and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the line c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Typ‌​e][*],CompanyElement‌ when the search pattern is CurrentPrincipalLegalEventAssociation. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
    – Alex Raj Kaliamoorthy
    Jan 4 at 14:19




    This is fine but my search pattern is CurrentPrincipalLegalEventAssociation and I cannot modify it to include the escape sequence. All I want is like grep or awk command that will print the line c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Typ‌​e][*],CompanyElement‌ when the search pattern is CurrentPrincipalLegalEventAssociation. While searching the file with this pattern I should tell the command to ignore the brackets of that line.
    – Alex Raj Kaliamoorthy
    Jan 4 at 14:19




    1




    1




    @AlexRajKaliamoorthy please see my updated answer using grep -F. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower case f) to read patterns directly from a file.
    – steeldriver
    Jan 4 at 14:27





    @AlexRajKaliamoorthy please see my updated answer using grep -F. Also, it shouldn't be necessary to iterate over a file containing search patterns - there is ` -f` option (lower case f) to read patterns directly from a file.
    – steeldriver
    Jan 4 at 14:27













    Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is just CurrentPrincipalLegalEventAssociation
    – Alex Raj Kaliamoorthy
    Jan 4 at 14:35




    Thanks for updating but the pattern what I have mentioned in my question does not have any brackets. It is just CurrentPrincipalLegalEventAssociation
    – Alex Raj Kaliamoorthy
    Jan 4 at 14:35




    1




    1




    @AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
    – Jesse_b
    Jan 4 at 15:10





    @AlexRajKaliamoorthy, Do you have a policy against modifying them or is it a principal thing? Because it's not impossible to do so the only thing stopping you from doing it is yourself -- or possibly some weird company policy? You shouldn't approach automation with a "can't do" attitude. "Whether you think you can, or you think you can't...you're right." -Henry Ford
    – Jesse_b
    Jan 4 at 15:10





    1




    1




    Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
    – Jesse_b
    Jan 4 at 15:16




    Also if you are receiving bad input from some upstream application, really the correct thing to do would be to fix that application rather than massage it's output, but I digress.
    – Jesse_b
    Jan 4 at 15:16












    up vote
    1
    down vote













    grep seems to do what you want.



    grep 'word' filename


    Will print every line in the file 'filename' that contains 'word'.






    share|improve this answer




















    • I have tried this already but if you see, my file has 1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition and I need only c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition . The line I need contains brackets and I want to ignore that while searching.
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:13















    up vote
    1
    down vote













    grep seems to do what you want.



    grep 'word' filename


    Will print every line in the file 'filename' that contains 'word'.






    share|improve this answer




















    • I have tried this already but if you see, my file has 1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition and I need only c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition . The line I need contains brackets and I want to ignore that while searching.
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:13













    up vote
    1
    down vote










    up vote
    1
    down vote









    grep seems to do what you want.



    grep 'word' filename


    Will print every line in the file 'filename' that contains 'word'.






    share|improve this answer












    grep seems to do what you want.



    grep 'word' filename


    Will print every line in the file 'filename' that contains 'word'.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 4 at 14:08









    sapensadler

    48016




    48016











    • I have tried this already but if you see, my file has 1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition and I need only c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition . The line I need contains brackets and I want to ignore that while searching.
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:13

















    • I have tried this already but if you see, my file has 1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition and I need only c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition . The line I need contains brackets and I want to ignore that while searching.
      – Alex Raj Kaliamoorthy
      Jan 4 at 14:13
















    I have tried this already but if you see, my file has 1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition and I need only c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition . The line I need contains brackets and I want to ignore that while searching.
    – Alex Raj Kaliamoorthy
    Jan 4 at 14:13





    I have tried this already but if you see, my file has 1097,agg.listgroup,CurrentPrincipalLegalEventAssociation,CompanyElementDefinition c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition and I need only c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition . The line I need contains brackets and I want to ignore that while searching.
    – Alex Raj Kaliamoorthy
    Jan 4 at 14:13











    up vote
    0
    down vote













    Using the following, the file output appears in next line in the file after pattern search line.



    sed -n '/CurrentPrincipal[MRC]/p' filename | sed -n '2p' 


    Output



    d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition 



    sed -n '/CurrentPrincipalLegalEventAssociation/,+1p' l.txt | sed -n '2p'


    Output



    c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition





    share|improve this answer


























      up vote
      0
      down vote













      Using the following, the file output appears in next line in the file after pattern search line.



      sed -n '/CurrentPrincipal[MRC]/p' filename | sed -n '2p' 


      Output



      d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition 



      sed -n '/CurrentPrincipalLegalEventAssociation/,+1p' l.txt | sed -n '2p'


      Output



      c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition





      share|improve this answer
























        up vote
        0
        down vote










        up vote
        0
        down vote









        Using the following, the file output appears in next line in the file after pattern search line.



        sed -n '/CurrentPrincipal[MRC]/p' filename | sed -n '2p' 


        Output



        d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition 



        sed -n '/CurrentPrincipalLegalEventAssociation/,+1p' l.txt | sed -n '2p'


        Output



        c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition





        share|improve this answer














        Using the following, the file output appears in next line in the file after pattern search line.



        sed -n '/CurrentPrincipal[MRC]/p' filename | sed -n '2p' 


        Output



        d4f170,atom.list,CurrentPrincipal[MRC][Type][*],CompanyElementDefinition 



        sed -n '/CurrentPrincipalLegalEventAssociation/,+1p' l.txt | sed -n '2p'


        Output



        c755ad,atom.list,CurrentPrincipal[LegalEventAssociation][Type][*],CompanyElementDefinition






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 5 at 11:59









        grg

        1857




        1857










        answered Jan 4 at 16:06









        Praveen Kumar BS

        1,010128




        1,010128






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f414774%2fhow-to-print-the-line-from-a-file-that-contains-the-matching-characters-in-the-p%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?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay