Need to match pattern in KSH while parsing lines from file

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











up vote
0
down vote

favorite












FILE_CENT="/etc/nsswitch.conf"

if [[ $OS = 'Linux' ]]; then
if [[ -e $FILE_CENT ]]; then
logInfo "nsswitch.conf found in $OS, Proceeding further..."
while read -r LINE
do
if [[ `echo $LINE | sed '/^passwd/'` ]]; then
myarrlin=($LINE)
logInfo "ARRAY VALUES : $myarrlin[0],$myarrlin[1],$myarrlin[2]"
if [[ `echo $myarrlin[1] | egrep -s "centrify$|^centrifydc$"` || `echo $myarrlin[2] | egrep -s "centrify$|^centrifydc$"` ]]; then
IS_ADMIN_ENT_ACC=3
CENT=1
logInfo "Centrify is enabled with $OS"
else
CENT=0
logInfo "Centrify is disabled with $OS"
fi
fi
done < $FILE_CENT
else
logInfo "nsswitch.conf does not exist in $OS, cannot fetch CENTRIFY information!"
fi
fi


Here, I am using sed and also egrep for pattern matching, but neither of them is giving me correct results.



Also, I am not sure if I can use regex with egrep? Struggling with pattern matching in KSH.



Input :
enter image description here










share|improve this question



















  • 1




    Pls show input sample data, incorrect, and correct results.
    – RudiC
    Aug 8 at 12:42










  • @RudiC Added the snapshot.
    – Dipit Sethi
    Aug 8 at 12:54










  • If my answer solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Sep 2 at 11:40














up vote
0
down vote

favorite












FILE_CENT="/etc/nsswitch.conf"

if [[ $OS = 'Linux' ]]; then
if [[ -e $FILE_CENT ]]; then
logInfo "nsswitch.conf found in $OS, Proceeding further..."
while read -r LINE
do
if [[ `echo $LINE | sed '/^passwd/'` ]]; then
myarrlin=($LINE)
logInfo "ARRAY VALUES : $myarrlin[0],$myarrlin[1],$myarrlin[2]"
if [[ `echo $myarrlin[1] | egrep -s "centrify$|^centrifydc$"` || `echo $myarrlin[2] | egrep -s "centrify$|^centrifydc$"` ]]; then
IS_ADMIN_ENT_ACC=3
CENT=1
logInfo "Centrify is enabled with $OS"
else
CENT=0
logInfo "Centrify is disabled with $OS"
fi
fi
done < $FILE_CENT
else
logInfo "nsswitch.conf does not exist in $OS, cannot fetch CENTRIFY information!"
fi
fi


Here, I am using sed and also egrep for pattern matching, but neither of them is giving me correct results.



Also, I am not sure if I can use regex with egrep? Struggling with pattern matching in KSH.



Input :
enter image description here










share|improve this question



















  • 1




    Pls show input sample data, incorrect, and correct results.
    – RudiC
    Aug 8 at 12:42










  • @RudiC Added the snapshot.
    – Dipit Sethi
    Aug 8 at 12:54










  • If my answer solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Sep 2 at 11:40












up vote
0
down vote

favorite









up vote
0
down vote

favorite











FILE_CENT="/etc/nsswitch.conf"

if [[ $OS = 'Linux' ]]; then
if [[ -e $FILE_CENT ]]; then
logInfo "nsswitch.conf found in $OS, Proceeding further..."
while read -r LINE
do
if [[ `echo $LINE | sed '/^passwd/'` ]]; then
myarrlin=($LINE)
logInfo "ARRAY VALUES : $myarrlin[0],$myarrlin[1],$myarrlin[2]"
if [[ `echo $myarrlin[1] | egrep -s "centrify$|^centrifydc$"` || `echo $myarrlin[2] | egrep -s "centrify$|^centrifydc$"` ]]; then
IS_ADMIN_ENT_ACC=3
CENT=1
logInfo "Centrify is enabled with $OS"
else
CENT=0
logInfo "Centrify is disabled with $OS"
fi
fi
done < $FILE_CENT
else
logInfo "nsswitch.conf does not exist in $OS, cannot fetch CENTRIFY information!"
fi
fi


Here, I am using sed and also egrep for pattern matching, but neither of them is giving me correct results.



Also, I am not sure if I can use regex with egrep? Struggling with pattern matching in KSH.



Input :
enter image description here










share|improve this question















FILE_CENT="/etc/nsswitch.conf"

if [[ $OS = 'Linux' ]]; then
if [[ -e $FILE_CENT ]]; then
logInfo "nsswitch.conf found in $OS, Proceeding further..."
while read -r LINE
do
if [[ `echo $LINE | sed '/^passwd/'` ]]; then
myarrlin=($LINE)
logInfo "ARRAY VALUES : $myarrlin[0],$myarrlin[1],$myarrlin[2]"
if [[ `echo $myarrlin[1] | egrep -s "centrify$|^centrifydc$"` || `echo $myarrlin[2] | egrep -s "centrify$|^centrifydc$"` ]]; then
IS_ADMIN_ENT_ACC=3
CENT=1
logInfo "Centrify is enabled with $OS"
else
CENT=0
logInfo "Centrify is disabled with $OS"
fi
fi
done < $FILE_CENT
else
logInfo "nsswitch.conf does not exist in $OS, cannot fetch CENTRIFY information!"
fi
fi


Here, I am using sed and also egrep for pattern matching, but neither of them is giving me correct results.



Also, I am not sure if I can use regex with egrep? Struggling with pattern matching in KSH.



Input :
enter image description here







sed grep ksh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 2 at 11:40









Jeff Schaller

32.4k849110




32.4k849110










asked Aug 8 at 12:24









Dipit Sethi

63




63







  • 1




    Pls show input sample data, incorrect, and correct results.
    – RudiC
    Aug 8 at 12:42










  • @RudiC Added the snapshot.
    – Dipit Sethi
    Aug 8 at 12:54










  • If my answer solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Sep 2 at 11:40












  • 1




    Pls show input sample data, incorrect, and correct results.
    – RudiC
    Aug 8 at 12:42










  • @RudiC Added the snapshot.
    – Dipit Sethi
    Aug 8 at 12:54










  • If my answer solved your problem, please accept it by clicking the checkmark next to it. Thank you!
    – Jeff Schaller
    Sep 2 at 11:40







1




1




Pls show input sample data, incorrect, and correct results.
– RudiC
Aug 8 at 12:42




Pls show input sample data, incorrect, and correct results.
– RudiC
Aug 8 at 12:42












@RudiC Added the snapshot.
– Dipit Sethi
Aug 8 at 12:54




@RudiC Added the snapshot.
– Dipit Sethi
Aug 8 at 12:54












If my answer solved your problem, please accept it by clicking the checkmark next to it. Thank you!
– Jeff Schaller
Sep 2 at 11:40




If my answer solved your problem, please accept it by clicking the checkmark next to it. Thank you!
– Jeff Schaller
Sep 2 at 11:40










1 Answer
1






active

oldest

votes

















up vote
1
down vote













Consider simplifying your logic to simply asking if the string "centrify" is in the "passwd:" line of /etc/nsswitch.conf. Replace the entire while loop with:



if grep -q '^passwd:.*centrify' /etc/nsswitch.conf
then
IS_ADMIN_ENT_ACC=3
CENT=1
logInfo "Centrify is enabled with $OS"
else
CENT=0
logInfo "Centrify is disabled with $OS"
fi





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%2f461276%2fneed-to-match-pattern-in-ksh-while-parsing-lines-from-file%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Consider simplifying your logic to simply asking if the string "centrify" is in the "passwd:" line of /etc/nsswitch.conf. Replace the entire while loop with:



    if grep -q '^passwd:.*centrify' /etc/nsswitch.conf
    then
    IS_ADMIN_ENT_ACC=3
    CENT=1
    logInfo "Centrify is enabled with $OS"
    else
    CENT=0
    logInfo "Centrify is disabled with $OS"
    fi





    share|improve this answer
























      up vote
      1
      down vote













      Consider simplifying your logic to simply asking if the string "centrify" is in the "passwd:" line of /etc/nsswitch.conf. Replace the entire while loop with:



      if grep -q '^passwd:.*centrify' /etc/nsswitch.conf
      then
      IS_ADMIN_ENT_ACC=3
      CENT=1
      logInfo "Centrify is enabled with $OS"
      else
      CENT=0
      logInfo "Centrify is disabled with $OS"
      fi





      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        Consider simplifying your logic to simply asking if the string "centrify" is in the "passwd:" line of /etc/nsswitch.conf. Replace the entire while loop with:



        if grep -q '^passwd:.*centrify' /etc/nsswitch.conf
        then
        IS_ADMIN_ENT_ACC=3
        CENT=1
        logInfo "Centrify is enabled with $OS"
        else
        CENT=0
        logInfo "Centrify is disabled with $OS"
        fi





        share|improve this answer












        Consider simplifying your logic to simply asking if the string "centrify" is in the "passwd:" line of /etc/nsswitch.conf. Replace the entire while loop with:



        if grep -q '^passwd:.*centrify' /etc/nsswitch.conf
        then
        IS_ADMIN_ENT_ACC=3
        CENT=1
        logInfo "Centrify is enabled with $OS"
        else
        CENT=0
        logInfo "Centrify is disabled with $OS"
        fi






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 8 at 12:49









        Jeff Schaller

        32.4k849110




        32.4k849110



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461276%2fneed-to-match-pattern-in-ksh-while-parsing-lines-from-file%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

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

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?