Check if the particular string is present in a output of shell script using shell command












0














I have a shell script (test1.sh) which returns the following output



 Employee ID          emp Type  return type  Admin User
us321000034006755 ITdept access Itadminuser


I wanted to check if the output contains string ITdept for that I have used the following:



if ./test1.sh | grep -q 'ITdept'; 
then
echo "found"
else
echo "Not found"
fi


Along with this I wanted to check the the strings Employee ID us321000034006755 too since it doesn't return any fruitful results with the command I am using not sure how to put this through. Am I missing something? any advice would be great










share|improve this question
























  • You need to check output from another script or inside test1.sh?
    – Egor Vasilyev
    Sep 13 '17 at 8:25
















0














I have a shell script (test1.sh) which returns the following output



 Employee ID          emp Type  return type  Admin User
us321000034006755 ITdept access Itadminuser


I wanted to check if the output contains string ITdept for that I have used the following:



if ./test1.sh | grep -q 'ITdept'; 
then
echo "found"
else
echo "Not found"
fi


Along with this I wanted to check the the strings Employee ID us321000034006755 too since it doesn't return any fruitful results with the command I am using not sure how to put this through. Am I missing something? any advice would be great










share|improve this question
























  • You need to check output from another script or inside test1.sh?
    – Egor Vasilyev
    Sep 13 '17 at 8:25














0












0








0







I have a shell script (test1.sh) which returns the following output



 Employee ID          emp Type  return type  Admin User
us321000034006755 ITdept access Itadminuser


I wanted to check if the output contains string ITdept for that I have used the following:



if ./test1.sh | grep -q 'ITdept'; 
then
echo "found"
else
echo "Not found"
fi


Along with this I wanted to check the the strings Employee ID us321000034006755 too since it doesn't return any fruitful results with the command I am using not sure how to put this through. Am I missing something? any advice would be great










share|improve this question















I have a shell script (test1.sh) which returns the following output



 Employee ID          emp Type  return type  Admin User
us321000034006755 ITdept access Itadminuser


I wanted to check if the output contains string ITdept for that I have used the following:



if ./test1.sh | grep -q 'ITdept'; 
then
echo "found"
else
echo "Not found"
fi


Along with this I wanted to check the the strings Employee ID us321000034006755 too since it doesn't return any fruitful results with the command I am using not sure how to put this through. Am I missing something? any advice would be great







linux shell-script awk grep






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 13 '17 at 9:33









Jeff Schaller

38.5k1053125




38.5k1053125










asked Sep 13 '17 at 8:03









Rebbeca

276




276












  • You need to check output from another script or inside test1.sh?
    – Egor Vasilyev
    Sep 13 '17 at 8:25


















  • You need to check output from another script or inside test1.sh?
    – Egor Vasilyev
    Sep 13 '17 at 8:25
















You need to check output from another script or inside test1.sh?
– Egor Vasilyev
Sep 13 '17 at 8:25




You need to check output from another script or inside test1.sh?
– Egor Vasilyev
Sep 13 '17 at 8:25










3 Answers
3






active

oldest

votes


















0














If the output will always contain only 2 lines - awk solution to check by multiple fields:



awk 'NR==2 { 
printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found"
}' <(sh ./test1.sh)





share|improve this answer





















  • This gives an error :-./test2.sh: line 7: syntax error near unexpected token (' ./test2.sh: line 7: }' <(sh ./test1.sh)'
    – Rebbeca
    Sep 13 '17 at 9:31












  • @Rebbeca, it's your script error: it indicates line 7. My script doesn't have 7 lines. Make sure you have specified the path to that shell script properly and there are no other errors in your shell script
    – RomanPerekhrest
    Sep 13 '17 at 9:41












  • this in the content of file in test2.sh:- ./test1.sh awk 'NR==2 { printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found" }' <(sh ./test1.sh)
    – Rebbeca
    Sep 13 '17 at 9:48










  • @Rebbeca, I've posted my approach as independent script. You should not have been put it into your script to call itself, that's pointless. Run the above awk script as is
    – RomanPerekhrest
    Sep 13 '17 at 9:51












  • Ah thanks a lot for pointing out the error :-) just one question if I need to check whether 'ITdept' or 'Emp ID' or one more lets say ('access') field is present what do I need to do should I increase the NR==3 and then add in awk as : printf "%s%sn",($1=="us321000034006755" && $2=="ITdept" && $3 "access")? "":"not ","found"
    – Rebbeca
    Sep 13 '17 at 9:57



















0














If you need to execute this check inside another script you can do that with something like this:



#!/bin/bash

var=$(./test1.sh | grep -c ITdept)

if [ $var > 0 ];
then
echo "found"
else
echo "Not found"
fi


Script counts the number of strings which contain one or more 'ITdept' words.



Or in single line (with awk):



./test1.sh | grep -c ITdept | awk '{if ($0==0) print "not found"; else if ($0>0) print "found"}'


correct me if I misunderstood your task.






share|improve this answer



















  • 1




    you can shorten grep | wc -l using grep -c
    – Archemar
    Sep 13 '17 at 9:01












  • Thanks for the help If I need another field in as acceptable in 'emp Type' ->ITdept or ITdomain then what to execute?
    – Rebbeca
    Sep 13 '17 at 9:20










  • You need only replace ITdept word after grep -c. If 'emp Type' contain spaces you need to place it in quotes
    – Egor Vasilyev
    Sep 13 '17 at 9:24





















0














Assuming that the output will contain the string us321000034006755(separator)ITdept:



if cmd | grep -q '[[:<:]]us321000034006755[[:>:]][[:space:]]*[[:<:]]ITdept[[:>:]]'; then
...
fi


If you have the two substrings in variables:



if cmd | grep -q "[[:<:]]$user_id[[:>:]][[:space:]]*[[:<:]]$user_dept[[:>:]]"; then
...
fi


The [[:<:]] and [[:>:]] will match on word boundaries.





It would be a lot easier to do this using awk, as RomanPerekhrest suggests, or



cmd | awk '$1 == "us321000034006755" && $2 == "ITdept" { print "found"; exit } END { print "not found" }'





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',
    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%2f391945%2fcheck-if-the-particular-string-is-present-in-a-output-of-shell-script-using-shel%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If the output will always contain only 2 lines - awk solution to check by multiple fields:



    awk 'NR==2 { 
    printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found"
    }' <(sh ./test1.sh)





    share|improve this answer





















    • This gives an error :-./test2.sh: line 7: syntax error near unexpected token (' ./test2.sh: line 7: }' <(sh ./test1.sh)'
      – Rebbeca
      Sep 13 '17 at 9:31












    • @Rebbeca, it's your script error: it indicates line 7. My script doesn't have 7 lines. Make sure you have specified the path to that shell script properly and there are no other errors in your shell script
      – RomanPerekhrest
      Sep 13 '17 at 9:41












    • this in the content of file in test2.sh:- ./test1.sh awk 'NR==2 { printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found" }' <(sh ./test1.sh)
      – Rebbeca
      Sep 13 '17 at 9:48










    • @Rebbeca, I've posted my approach as independent script. You should not have been put it into your script to call itself, that's pointless. Run the above awk script as is
      – RomanPerekhrest
      Sep 13 '17 at 9:51












    • Ah thanks a lot for pointing out the error :-) just one question if I need to check whether 'ITdept' or 'Emp ID' or one more lets say ('access') field is present what do I need to do should I increase the NR==3 and then add in awk as : printf "%s%sn",($1=="us321000034006755" && $2=="ITdept" && $3 "access")? "":"not ","found"
      – Rebbeca
      Sep 13 '17 at 9:57
















    0














    If the output will always contain only 2 lines - awk solution to check by multiple fields:



    awk 'NR==2 { 
    printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found"
    }' <(sh ./test1.sh)





    share|improve this answer





















    • This gives an error :-./test2.sh: line 7: syntax error near unexpected token (' ./test2.sh: line 7: }' <(sh ./test1.sh)'
      – Rebbeca
      Sep 13 '17 at 9:31












    • @Rebbeca, it's your script error: it indicates line 7. My script doesn't have 7 lines. Make sure you have specified the path to that shell script properly and there are no other errors in your shell script
      – RomanPerekhrest
      Sep 13 '17 at 9:41












    • this in the content of file in test2.sh:- ./test1.sh awk 'NR==2 { printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found" }' <(sh ./test1.sh)
      – Rebbeca
      Sep 13 '17 at 9:48










    • @Rebbeca, I've posted my approach as independent script. You should not have been put it into your script to call itself, that's pointless. Run the above awk script as is
      – RomanPerekhrest
      Sep 13 '17 at 9:51












    • Ah thanks a lot for pointing out the error :-) just one question if I need to check whether 'ITdept' or 'Emp ID' or one more lets say ('access') field is present what do I need to do should I increase the NR==3 and then add in awk as : printf "%s%sn",($1=="us321000034006755" && $2=="ITdept" && $3 "access")? "":"not ","found"
      – Rebbeca
      Sep 13 '17 at 9:57














    0












    0








    0






    If the output will always contain only 2 lines - awk solution to check by multiple fields:



    awk 'NR==2 { 
    printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found"
    }' <(sh ./test1.sh)





    share|improve this answer












    If the output will always contain only 2 lines - awk solution to check by multiple fields:



    awk 'NR==2 { 
    printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found"
    }' <(sh ./test1.sh)






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 13 '17 at 8:35









    RomanPerekhrest

    22.8k12346




    22.8k12346












    • This gives an error :-./test2.sh: line 7: syntax error near unexpected token (' ./test2.sh: line 7: }' <(sh ./test1.sh)'
      – Rebbeca
      Sep 13 '17 at 9:31












    • @Rebbeca, it's your script error: it indicates line 7. My script doesn't have 7 lines. Make sure you have specified the path to that shell script properly and there are no other errors in your shell script
      – RomanPerekhrest
      Sep 13 '17 at 9:41












    • this in the content of file in test2.sh:- ./test1.sh awk 'NR==2 { printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found" }' <(sh ./test1.sh)
      – Rebbeca
      Sep 13 '17 at 9:48










    • @Rebbeca, I've posted my approach as independent script. You should not have been put it into your script to call itself, that's pointless. Run the above awk script as is
      – RomanPerekhrest
      Sep 13 '17 at 9:51












    • Ah thanks a lot for pointing out the error :-) just one question if I need to check whether 'ITdept' or 'Emp ID' or one more lets say ('access') field is present what do I need to do should I increase the NR==3 and then add in awk as : printf "%s%sn",($1=="us321000034006755" && $2=="ITdept" && $3 "access")? "":"not ","found"
      – Rebbeca
      Sep 13 '17 at 9:57


















    • This gives an error :-./test2.sh: line 7: syntax error near unexpected token (' ./test2.sh: line 7: }' <(sh ./test1.sh)'
      – Rebbeca
      Sep 13 '17 at 9:31












    • @Rebbeca, it's your script error: it indicates line 7. My script doesn't have 7 lines. Make sure you have specified the path to that shell script properly and there are no other errors in your shell script
      – RomanPerekhrest
      Sep 13 '17 at 9:41












    • this in the content of file in test2.sh:- ./test1.sh awk 'NR==2 { printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found" }' <(sh ./test1.sh)
      – Rebbeca
      Sep 13 '17 at 9:48










    • @Rebbeca, I've posted my approach as independent script. You should not have been put it into your script to call itself, that's pointless. Run the above awk script as is
      – RomanPerekhrest
      Sep 13 '17 at 9:51












    • Ah thanks a lot for pointing out the error :-) just one question if I need to check whether 'ITdept' or 'Emp ID' or one more lets say ('access') field is present what do I need to do should I increase the NR==3 and then add in awk as : printf "%s%sn",($1=="us321000034006755" && $2=="ITdept" && $3 "access")? "":"not ","found"
      – Rebbeca
      Sep 13 '17 at 9:57
















    This gives an error :-./test2.sh: line 7: syntax error near unexpected token (' ./test2.sh: line 7: }' <(sh ./test1.sh)'
    – Rebbeca
    Sep 13 '17 at 9:31






    This gives an error :-./test2.sh: line 7: syntax error near unexpected token (' ./test2.sh: line 7: }' <(sh ./test1.sh)'
    – Rebbeca
    Sep 13 '17 at 9:31














    @Rebbeca, it's your script error: it indicates line 7. My script doesn't have 7 lines. Make sure you have specified the path to that shell script properly and there are no other errors in your shell script
    – RomanPerekhrest
    Sep 13 '17 at 9:41






    @Rebbeca, it's your script error: it indicates line 7. My script doesn't have 7 lines. Make sure you have specified the path to that shell script properly and there are no other errors in your shell script
    – RomanPerekhrest
    Sep 13 '17 at 9:41














    this in the content of file in test2.sh:- ./test1.sh awk 'NR==2 { printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found" }' <(sh ./test1.sh)
    – Rebbeca
    Sep 13 '17 at 9:48




    this in the content of file in test2.sh:- ./test1.sh awk 'NR==2 { printf "%s%sn",($1=="us321000034006755" && $2=="ITdept")? "":"not ","found" }' <(sh ./test1.sh)
    – Rebbeca
    Sep 13 '17 at 9:48












    @Rebbeca, I've posted my approach as independent script. You should not have been put it into your script to call itself, that's pointless. Run the above awk script as is
    – RomanPerekhrest
    Sep 13 '17 at 9:51






    @Rebbeca, I've posted my approach as independent script. You should not have been put it into your script to call itself, that's pointless. Run the above awk script as is
    – RomanPerekhrest
    Sep 13 '17 at 9:51














    Ah thanks a lot for pointing out the error :-) just one question if I need to check whether 'ITdept' or 'Emp ID' or one more lets say ('access') field is present what do I need to do should I increase the NR==3 and then add in awk as : printf "%s%sn",($1=="us321000034006755" && $2=="ITdept" && $3 "access")? "":"not ","found"
    – Rebbeca
    Sep 13 '17 at 9:57




    Ah thanks a lot for pointing out the error :-) just one question if I need to check whether 'ITdept' or 'Emp ID' or one more lets say ('access') field is present what do I need to do should I increase the NR==3 and then add in awk as : printf "%s%sn",($1=="us321000034006755" && $2=="ITdept" && $3 "access")? "":"not ","found"
    – Rebbeca
    Sep 13 '17 at 9:57













    0














    If you need to execute this check inside another script you can do that with something like this:



    #!/bin/bash

    var=$(./test1.sh | grep -c ITdept)

    if [ $var > 0 ];
    then
    echo "found"
    else
    echo "Not found"
    fi


    Script counts the number of strings which contain one or more 'ITdept' words.



    Or in single line (with awk):



    ./test1.sh | grep -c ITdept | awk '{if ($0==0) print "not found"; else if ($0>0) print "found"}'


    correct me if I misunderstood your task.






    share|improve this answer



















    • 1




      you can shorten grep | wc -l using grep -c
      – Archemar
      Sep 13 '17 at 9:01












    • Thanks for the help If I need another field in as acceptable in 'emp Type' ->ITdept or ITdomain then what to execute?
      – Rebbeca
      Sep 13 '17 at 9:20










    • You need only replace ITdept word after grep -c. If 'emp Type' contain spaces you need to place it in quotes
      – Egor Vasilyev
      Sep 13 '17 at 9:24


















    0














    If you need to execute this check inside another script you can do that with something like this:



    #!/bin/bash

    var=$(./test1.sh | grep -c ITdept)

    if [ $var > 0 ];
    then
    echo "found"
    else
    echo "Not found"
    fi


    Script counts the number of strings which contain one or more 'ITdept' words.



    Or in single line (with awk):



    ./test1.sh | grep -c ITdept | awk '{if ($0==0) print "not found"; else if ($0>0) print "found"}'


    correct me if I misunderstood your task.






    share|improve this answer



















    • 1




      you can shorten grep | wc -l using grep -c
      – Archemar
      Sep 13 '17 at 9:01












    • Thanks for the help If I need another field in as acceptable in 'emp Type' ->ITdept or ITdomain then what to execute?
      – Rebbeca
      Sep 13 '17 at 9:20










    • You need only replace ITdept word after grep -c. If 'emp Type' contain spaces you need to place it in quotes
      – Egor Vasilyev
      Sep 13 '17 at 9:24
















    0












    0








    0






    If you need to execute this check inside another script you can do that with something like this:



    #!/bin/bash

    var=$(./test1.sh | grep -c ITdept)

    if [ $var > 0 ];
    then
    echo "found"
    else
    echo "Not found"
    fi


    Script counts the number of strings which contain one or more 'ITdept' words.



    Or in single line (with awk):



    ./test1.sh | grep -c ITdept | awk '{if ($0==0) print "not found"; else if ($0>0) print "found"}'


    correct me if I misunderstood your task.






    share|improve this answer














    If you need to execute this check inside another script you can do that with something like this:



    #!/bin/bash

    var=$(./test1.sh | grep -c ITdept)

    if [ $var > 0 ];
    then
    echo "found"
    else
    echo "Not found"
    fi


    Script counts the number of strings which contain one or more 'ITdept' words.



    Or in single line (with awk):



    ./test1.sh | grep -c ITdept | awk '{if ($0==0) print "not found"; else if ($0>0) print "found"}'


    correct me if I misunderstood your task.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Sep 13 '17 at 9:04

























    answered Sep 13 '17 at 8:32









    Egor Vasilyev

    1,822129




    1,822129








    • 1




      you can shorten grep | wc -l using grep -c
      – Archemar
      Sep 13 '17 at 9:01












    • Thanks for the help If I need another field in as acceptable in 'emp Type' ->ITdept or ITdomain then what to execute?
      – Rebbeca
      Sep 13 '17 at 9:20










    • You need only replace ITdept word after grep -c. If 'emp Type' contain spaces you need to place it in quotes
      – Egor Vasilyev
      Sep 13 '17 at 9:24
















    • 1




      you can shorten grep | wc -l using grep -c
      – Archemar
      Sep 13 '17 at 9:01












    • Thanks for the help If I need another field in as acceptable in 'emp Type' ->ITdept or ITdomain then what to execute?
      – Rebbeca
      Sep 13 '17 at 9:20










    • You need only replace ITdept word after grep -c. If 'emp Type' contain spaces you need to place it in quotes
      – Egor Vasilyev
      Sep 13 '17 at 9:24










    1




    1




    you can shorten grep | wc -l using grep -c
    – Archemar
    Sep 13 '17 at 9:01






    you can shorten grep | wc -l using grep -c
    – Archemar
    Sep 13 '17 at 9:01














    Thanks for the help If I need another field in as acceptable in 'emp Type' ->ITdept or ITdomain then what to execute?
    – Rebbeca
    Sep 13 '17 at 9:20




    Thanks for the help If I need another field in as acceptable in 'emp Type' ->ITdept or ITdomain then what to execute?
    – Rebbeca
    Sep 13 '17 at 9:20












    You need only replace ITdept word after grep -c. If 'emp Type' contain spaces you need to place it in quotes
    – Egor Vasilyev
    Sep 13 '17 at 9:24






    You need only replace ITdept word after grep -c. If 'emp Type' contain spaces you need to place it in quotes
    – Egor Vasilyev
    Sep 13 '17 at 9:24













    0














    Assuming that the output will contain the string us321000034006755(separator)ITdept:



    if cmd | grep -q '[[:<:]]us321000034006755[[:>:]][[:space:]]*[[:<:]]ITdept[[:>:]]'; then
    ...
    fi


    If you have the two substrings in variables:



    if cmd | grep -q "[[:<:]]$user_id[[:>:]][[:space:]]*[[:<:]]$user_dept[[:>:]]"; then
    ...
    fi


    The [[:<:]] and [[:>:]] will match on word boundaries.





    It would be a lot easier to do this using awk, as RomanPerekhrest suggests, or



    cmd | awk '$1 == "us321000034006755" && $2 == "ITdept" { print "found"; exit } END { print "not found" }'





    share|improve this answer




























      0














      Assuming that the output will contain the string us321000034006755(separator)ITdept:



      if cmd | grep -q '[[:<:]]us321000034006755[[:>:]][[:space:]]*[[:<:]]ITdept[[:>:]]'; then
      ...
      fi


      If you have the two substrings in variables:



      if cmd | grep -q "[[:<:]]$user_id[[:>:]][[:space:]]*[[:<:]]$user_dept[[:>:]]"; then
      ...
      fi


      The [[:<:]] and [[:>:]] will match on word boundaries.





      It would be a lot easier to do this using awk, as RomanPerekhrest suggests, or



      cmd | awk '$1 == "us321000034006755" && $2 == "ITdept" { print "found"; exit } END { print "not found" }'





      share|improve this answer


























        0












        0








        0






        Assuming that the output will contain the string us321000034006755(separator)ITdept:



        if cmd | grep -q '[[:<:]]us321000034006755[[:>:]][[:space:]]*[[:<:]]ITdept[[:>:]]'; then
        ...
        fi


        If you have the two substrings in variables:



        if cmd | grep -q "[[:<:]]$user_id[[:>:]][[:space:]]*[[:<:]]$user_dept[[:>:]]"; then
        ...
        fi


        The [[:<:]] and [[:>:]] will match on word boundaries.





        It would be a lot easier to do this using awk, as RomanPerekhrest suggests, or



        cmd | awk '$1 == "us321000034006755" && $2 == "ITdept" { print "found"; exit } END { print "not found" }'





        share|improve this answer














        Assuming that the output will contain the string us321000034006755(separator)ITdept:



        if cmd | grep -q '[[:<:]]us321000034006755[[:>:]][[:space:]]*[[:<:]]ITdept[[:>:]]'; then
        ...
        fi


        If you have the two substrings in variables:



        if cmd | grep -q "[[:<:]]$user_id[[:>:]][[:space:]]*[[:<:]]$user_dept[[:>:]]"; then
        ...
        fi


        The [[:<:]] and [[:>:]] will match on word boundaries.





        It would be a lot easier to do this using awk, as RomanPerekhrest suggests, or



        cmd | awk '$1 == "us321000034006755" && $2 == "ITdept" { print "found"; exit } END { print "not found" }'






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 13 '17 at 9:15

























        answered Sep 13 '17 at 8:43









        Kusalananda

        121k16229372




        121k16229372






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f391945%2fcheck-if-the-particular-string-is-present-in-a-output-of-shell-script-using-shel%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

            Morgemoulin

            Scott Moir

            Souastre