Need to match pattern in KSH while parsing lines from file
Clash 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 :
sed grep ksh
add a comment |Â
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 :
sed grep ksh
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
add a comment |Â
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 :
sed grep ksh
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 :
sed grep ksh
sed grep ksh
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Aug 8 at 12:49
Jeff Schaller
32.4k849110
32.4k849110
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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