0

First Query:

i have a text file username.txt contains

user1
user2
user3

My Bash file is as follows > test.sh

#!/bin/bash
# REMOVE user which donot have any COMBLIMIT
num=0
cat /tmp/username.txt | while read users
do
num=$[$num+1]
USERID=`echo $users | awk '{print $1}'`
SRVID=`mysql -uxxx -pxxx -e "use radius; SELECT srvid FROM radius.rm_users WHERE rm_users.username = '$USERID';" |awk 'FNR == 2 {print $1}'`
COMBLIMITCHECK=`mysql -uxxx -pxxx -e "use radius; SELECT limitcomb FROM rm_services WHERE srvid = '$SRVID';" |awk 'FNR == 2 {print $1}'`
if [[ $COMBLIMITCHECK -eq "1" ]]; then
echo "$USERID have Quota limit = 1"
else
echo "$USERID have no Quota Limitations = 0 , So removing it from the users list."
sed -i '/\$USERID\>/d' /tmp/username.txt
fi
done

sed -i '/\$USERID\>/d' /tmp/username.txt >> This command in bash is not removing the exact matched username. I want to delete line which contains specific username (variable).

Second Query:

File contains following lines

cOke is bad 
diet-COKE 
cokeisgood

How can i cat this file and search for any word which contains "coke" in it regardless of lower or upper case.

1

sed -i '/\$USERID>/d' /tmp/username.txt

You have enclosed your sed expression in ' single quotes. This will stop the expansion of $USERID and cause it to be used as a string literal. You should enclose the sed expression in " double quotes to allow the variable expansion.

File contains following lines

The -i switch to grep ignores case.

You can also use I (capital i) in a sed expression for (this may be a GNU sed thing)

echo "cOke is bad" | sed -n "/coke/Ip" 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.