Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi All,
i am writing a script, here is the piece of code:
Code:
SET_DIAL_DTLS()
{
SERACH_ID=$1
DNIS_VAL=$(grep "$SERACH_ID" $DIAL_FEED_DTLS|awk -F '|' '{print $1}')
if [[ -z "${DNIS_VAL}" ]]
then
echo "DNIS_VAL is Empty...!!"
DNIS_VAL="No Entry Found"
else
echo "DNIS_VAL has some value...!!"
DNIS_VAL=${DNIS_VAL}
fi
CID_VAL=$(grep "$SERACH_ID" $DIAL_FEED_DTLS|awk -F '|' '{print $2}')
if [[ -z "${CID_VAL}" ]]
then
echo "CID_VAL is Empty...!!"
CID_VAL="No Entry Found"
else
echo "CID_VAL has some value...!!"
DNIS_VAL=${CID_VAL}
fi
TOT_TRNXS_VAL=$(grep "$SERACH_ID" $DIAL_FEED_DTLS|awk -F '|' '{print $3}')
if [[ -z "${TOT_TRNXS_VAL}" ]]
then
echo "TOT_TRNXS_VAL is Empty...!!"
TOT_TRNXS_VAL="No Entry Found"
else
echo "TOT_TRNXS_VAL has some value...!!"
TOT_TRNXS_VAL=${TOT_TRNXS_VAL}
fi
GOOD_TRNXS_VAL=$(grep "$SERACH_ID" $DIAL_FEED_DTLS|awk -F '|' '{print $4}')
if [[ -z "${GOOD_TRNXS_VAL}" ]]
then
echo "GOOD_TRNXS_VAL is Empty...!!"
GOOD_TRNXS_VAL="No Entry Found"
else
echo "GOOD_TRNXS_VAL has some value...!!"
GOOD_TRNXS_VAL=${GOOD_TRNXS_VAL}
fi
BAD_TRNXS_VAL=$(grep "$SERACH_ID" $DIAL_FEED_DTLS|awk -F '|' '{print $5}')
if [[ -z "${BAD_TRNXS_VAL}" ]]
then
echo "BAD_TRNXS_VAL is Empty...!!"
BAD_TRNXS_VAL="No Entry Found"
else
echo "BAD_TRNXS_VAL has some value...!!"
BAD_TRNXS_VAL=${BAD_TRNXS_VAL}
fi
}
is there a better way to write the above function, can we reduce this piece of code?
Or even ditch the grep all together and just use awk.
One consideration for the array would be, how do you know which items did not appear?
The print from the awk script can indicate empty entries... In fact, it may even carry out the logic of the rest of the script setting the values really desired rather than the raw values that have to be retested.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.