Replace string with asterisk(*) in variable

I was trying to replace a string ( for eg - @@asterisk@@ to * ) in variable using

cat $INFILE  | while read LINE
do
    stmt1=`echo $LINE | sed 's/@@asterisk@@/\*/g'`
    stmt=$stmt' '$stmt1
    stmt2=`echo $LINE`
    STATEMENT=$STATEMENT' '$stmt2
done
echo 'Statement with sed -- > ' $stmt 
echo 'Statement without sed -- > ' $STATEMENT 

Output I am getting is

Statement with sed -- >
Statement without sed -- >  INSERT INTO table1 SELECT @@ASTERISK@@ FROM table2

Seems sed is not working.. Appreciate if someone say what is wrong in this.

Thanks in advance

Actually nothing is wrong in your replacement, but you fail to protect your variables content until the output:

variable_with_glob='*'
print - "compare this: $variable_with_glob"
print - "to this:" $variable_with_glob

I hope this helps.

bakunin

Or do something with turning off glob
ksh turns off globbing with set -f or set noglob

#!/bin/ksh
cat $INFILE | while read LINE 
do 
   set -f
   stmt1=`echo $LINE | sed 's/@@asterisk@@/\*/g'` 
   stmt=$stmt' '$stmt1 stmt2=`echo $LINE` 
   STATEMENT=$STATEMENT ' ' $stmt2 
   set +f
done
print "$STATEMENT"

Make sure you turn globbing back on - it will affect subsequent code. Ver badly -- if it is off.

Thanks ... tried set -f & set +f , but it didn't work ..

It looks like you have this in your input file:

INSERT INTO table1 SELECT @@ASTERISK@@ FROM table2

Your sed command is looking for "@@asterisk@@" instead of "@@ASTERISK@@". Is that the problem?

Also, make sure you use double-quotes on the last two echos like this or the "*" will be replaced with a list of files in the current directory.

echo "Statement with sed -- >  $stmt "
echo "Statement without sed -- >  $STATEMENT"

---------- Post updated at 02:28 PM ---------- Previous update was at 02:23 PM ----------

This is what I get now with your script. I named it "test" with the INFILE=test.in

host:/home:$ ls -l test*
-rwxr-xr-x    1 root     system          267 Apr 19 14:25 test
-rw-r--r--    1 root     system           51 Apr 19 14:24 test.in

host:/home:$ cat ./test.in
INSERT INTO table1 SELECT @@ASTERISK@@ FROM table2

host:/home:$ cat ./test
INFILE=./test.in
cat $INFILE | while read LINE
do
        stmt1=`echo $LINE | sed 's/@@ASTERISK@@/\*/g'`
        stmt=$stmt' '$stmt1
        stmt2=`echo $LINE`
        STATEMENT=$STATEMENT' '$stmt2
done
echo "Statement with sed -- >  $stmt "
echo "Statement without sed -- >  $STATEMENT"

host:/home:$ ./test
Statement with sed -- >   INSERT INTO table1 SELECT * FROM table2
Statement without sed -- >   INSERT INTO table1 SELECT @@ASTERISK@@ FROM table2

host:/home:$

Thanks to all ... it worked like a champ.

Shyam