Sed-- command help required

Hi Gurus,

I have a small requirement.
Let suppose i have a file test.txt
test.txt contains
Dispatched date = '2008-04-08'
Name = 'Logers'

Now i want to add one more line to it as Number of Responses = "$a"
$a will be chnaging dynamically which i had grepped it in the script.

Now i want to add this line to test.txt

suppose now a holds the value 20 my output should be

Dispatched date = '2008-04-08'
Name = 'Logers'
Number of Responses = 20

Can you help me out how to get the required solution by using sed command

I think it can be possible ny using sed 2 times Can anyone give me a example code to get the requirement done

Hi
You can try like:

grep "Delete/Rename/Compress Log Files" test.txt  | awk '{print "Number of Responses " $1}' >>test.txt

What is "Delete/Rename/Compress Log Files" in the above command
What should be kept in place of that?

Try this one:

awk '/Name = \047Logers\047/{print $0;print "Number of Responses = 20";next}1' test.txt

Regards

tHANKS FR UR REPLY

But here no of responses = 20 is not constant one it will be a variable there i shouls get the value of variable a

NAME ALSO VARIES

Pssandeep, please do not uppercase your reply or use IM-speak!

Here is a short example which shows you how to do what you asked for using sed

#!/usr/bin/ksh

TMP1=file1.$$
TMP2=file2.$$

# number of responses
A=20

cat <<EOT >$TMP1
Dispatched date = '2008-04-08'
Name = 'Logers'
EOT

echo "====================="
cat $TMP1
echo "====================="

sed '$a\
Number of Responses = '"${A}"'
' $TMP1 > $TMP2

cat $TMP2
echo "====================="


rm $TMP1 $TMP2
exit 0

Here's an example how you can use variables with awk:

#!/usr/bin/ksh

MyName="Logers"
MyNum="20"

awk -v name=$MyName -v num=$MyNum '
$0=="Name = \047"name"\047" {print $0;print "Number of Responses = "num;next}1
' test.txt

Regards