troubleshooting Question

Issue with awk in cmd substitution with if

Avatar of Watnog
WatnogFlag for Belgium asked on
* kshShell Scripting* AWK
7 Comments1 Solution86 ViewsLast Modified:
Dear Experts,

Can you please help me with this one?
i have below snippet...
I want to extract

session = MMECHJ-1
and
uproc =MMECHJ-1H


prompt>cat a
#!/usr/bin/ksh
set -x

LINE="MMECHJ-1 MMECHJ-1H P_PM43CEXP EXECUTING 19/03/2020 205814 19/03/2020 205814 LBKU01G SYS_BATCH 000000 100 0001093 0014704 19/03/2020 root 000 000 00 0013904"

if [[ $(echo $LINE | awk -F"-" '{ print $1"-" $2 }') == "MMECHJ-1" ]] ; then
session=$(echo "$LINE" | awk -F"-" '{ print $1"-"$2 }')
uproc=$(echo "$LINE" | awk -F"-" '{ print $3"-"$4 }' | awk -F";" '{ print $1 }')
fi


echo "$session"
echo "$uproc"


Below how it works out:
awk -F"-" '{ print $1"-" $2 }' results in "MMECHJ-1 MMECHJ" , while seperator is the dash ;;.

prompt>./a
+ LINE=MMECHJ-1 MMECHJ-1H P_PM43CEXP EXECUTING 19/03/2020 205814 19/03/2020 205814 LBKU01G SYS_BATCH 000000 100 0001093 0014704 19/03/2020 root 000 000 00 0013904
+ awk -F- { print $1"-" $2 }
+ echo MMECHJ-1 MMECHJ-1H P_PM43CEXP EXECUTING 19/03/2020 205814 19/03/2020 205814 LBKU01G SYS_BATCH 000000 100 0001093 0014704 19/03/2020 root 000 000 00 0013904
+ [[ MMECHJ-1 MMECHJ == MMECHJ-1 ]]
+ echo

+ echo

[bex1000@hn5219] /crelan/exp/prod/teste_production/teste_pascal/INC >

What's happening? This is ksh on aix.
:-~
Thanks again,
W.
ASKER CERTIFIED SOLUTION
MURUGESAN N
Requirement analysis,Application Development,Automation Management.Senior technical manager 16 years 11 months.Knowledge transfer 18 years.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros