I have a following string.
"machine=IFLMUD5HP0581&group1=Stop"
I have created 2 variables namely machine and action.
machine should contain
IFLMUD5HP0581
action should contain
Stop
How do i write a script for the same.
I have a following string.
"machine=IFLMUD5HP0581&group1=Stop"
I have created 2 variables namely machine and action.
machine should contain
IFLMUD5HP0581
action should contain
Stop
How do i write a script for the same.
amit@softpc142108 ars $ echo "machine=IFLMUD5HP0581&group1=Stop" | cut -d '=' -f2 |cut -d '&' -f1
IFLMUD5HP0581
amit@softpc142108 ars $ echo "machine=IFLMUD5HP0581&group1=Stop" | cut -d '=' -f3
Stop
echo "machine=IFLMUD5HP0581&group1=Stop"|sed 's/.*=\(.[^=]*\)\(.*\)\(&.[^=]*\)=\(.[^=]*\)/\1 \4/'
echo "machine=IFLMUD5HP0581&group1=Stop"|sed 's/.[^=]*=//;s/&.[^=]*=/ /'
use eval :
STRING="machine=IFLMUD5HP0581&group1=Stop"
eval ${STRING#*&}
eval ${STRING%&*}
echo "machine = $machine - group1 = $group1"
Try this:
echo "machine=IFLMUD5HP0581&group1=Stop" |awk -F"[=&]" '{ print $2,$4}' | read machine action
echo $machine
echo $action
Thank you very much for all of your support.
awk -F '=' '{ print $2 " "$3}' filename | awk -F '&' '{ print $1}'
awk -F '=' '{ print $2 " "$3}' filename | awk '{ print $2}'
IFS="&"
while read line;do
set $line
while [ $# -gt 0 ];do
eval $1
shift
done
done < yourfile
echo $machine
echo $group1