Grep issue

Hi All
I have a file containing following records:

$HEW_TGT_DB2_USER=hbme_bi2
$prmAttunityUser=ais
$DS_USER=hbme_bi2
$prmStgUser=hbme_bi2
$prmuser=hbme_bi2
$prmStgPass=hbme_bi2
$prmpwd=hbme_bi2
$prmAttunityUser=ais

Say suppose the name of the file is test4.txt
When i fire this command on linux

ret=`grep \^$prmAttunityUser\= test4.txt`
echo $ret

The value in "ret" is blank could you all please help me in troubleshooting this where as i want that "ret" variable should contain output like this

prmAttunityUser=ais
It should be excluding the $ sign

Thanks

It will be having 2 values bcoz your infile has two lines of prmAttunityUser..

$ ret=$(grep "^\$prmAttunityUser=" infile | sed 's/\$//g')
$ echo $ret
prmAttunityUser=ais prmAttunityUser=ais

One more ..

$ ret=$(nawk '/\$prmAttunityUser=/{sub(/\$/,"");print}' infile)
$ echo $ret
prmAttunityUser=ais prmAttunityUser=ais

Actually the error is the unquoted $. Just try it from an interactive shell:

mute@eeepc:~$ grep \^$prmAttunityUser\= file2
mute@eeepc:~$ grep '^$prmAttunityUser=' file2
$prmAttunityUser=ais
$prmAttunityUser=ais

Single quotes are best for such things unless you expect to expand a variable.
Then you should always quote expansions.

ret=`grep '^$prmAttunityUser=' file2`
echo "$ret"

$ret now contains two lines. Can you operate with that, or will you need a for-loop?

mute@eeepc:~$ cat for
#!/bin/sh

grep '^$prmAttunityUser=' file2 | sed 's/^.//' | while read ret; do
	printf "Do something with: [[%s]]\n" "$ret"
done
mute@eeepc:~$ ./for
Do something with: [[prmAttunityUser=ais]]
Do something with: [[prmAttunityUser=ais]]

If you need more help, please say which shell you're programming for.