I need to read a line from a file and strip the characters from it and compare the stripped value with the value I pass to the script while executing it. Below is the code for the same. But when i execute the code, it is throwing an error.
#!/bin/ksh
. /home/.i_env
FOLDER_NAME=$1
APP=$2
while read line
grp=${line%_*}
if [ $APP -eq $grp ]; then
group=${line%,*}
perm=${line#*,}
# "doing something here using above variables"
fi
done < i_groups.txt
#!/bin/ksh
. /home/.i_env
FOLDER_NAME=$1
APP=$2
while read line
do
grp=${line%_*}
if [ $APP -eq $grp ]; then
group=${line%,*}
perm=${line#*,}
# "doing something here using above variables"
fi
done < i_groups.txt
oops. thats a good catch. now the script is giving a different error.
my requirement is to strip out the first 3 characters from the input file and compare it with the value i pass, if it is same, then do something, otherwise look for the next value.
script is working fine if the values in my input file has only one '_' in between (ex: CTF_DEV).
But if there are 2 underscores (ex: CTF_DEV_GRP) then it is not giving expected value.
#!/bin/ksh
. /home/.i_env
FOLDER_NAME=$1
APP=$2
while read line
do
grp=$(echo "$line"|sed 's/^\(...\).*/\1/' )
if [ "$APP" == "$grp" ]; then
group=${line%,*}
perm=${line#*,}
# "doing something here using above variables"
fi
done < i_groups.txt