We help IT Professionals succeed at work.
Get Started

Issue with awk in cmd substitution with if

Watnog
Watnog asked
on
82 Views
Last Modified: 2020-03-27
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"

Open in new window



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 >

Open in new window


What's happening? This is ksh on aix.
:-~
Thanks again,
W.
Comment
Watch Question
Application Development and Automation Management
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE