How to use sed to put string end of line?

I have several file as below, and i want to put .txt to specific text contain ^main=EXE^cmd=run script /usr/prog/bd_,

file1

7.9102 12.1528 16.3672 7.4002
^main=EXE^cmd=run script /usr/prog/bd_123^"
line 16.3672 7.3134 17.8711 6.0981 

file 2

7.9102 12.1528 16.3672 7.4002 
^main=EXE^cmd=run script /usr/prog/bd_148^"
5.6836 17.5998 19.3566 15.5998 

file 3

1.10001
^main=EXE^cmd=run script /usr/prog/bd_165^"
1.10001.888.20.3

I want my output file

file1

7.9102 12.1528 16.3672 7.4002
^main=EXE^cmd=run script /usr/prog/bd_123.txt^"
line 16.3672 7.3134 17.8711 6.0981 

file 2

7.9102 12.1528 16.3672 7.4002 
^main=EXE^cmd=run script /usr/prog/bd_148.txt^"
5.6836 17.5998 19.3566 15.5998 

file 3

1.10001
^main=EXE^cmd=run script /usr/prog/bd_165.txt^"
1.10001.888.20.3

I saw the same topic already, looks like a homework.

please help me

---------- Post updated at 09:53 PM ---------- Previous update was at 09:52 PM ----------

please help me

Hi,
Try this one,

sed 's/$/addstr/g' file

Cheers,
Ranga:-)

thanks for help but using this code will put .txt all of the end of line..i want to put the .txt in the specific line

Hi,

you can use awk to match the pattern and add the string at the end of line,

awk 'BEGIN{OFS="";}$0 !~ /pattern/{print;}$0 ~ /pattern/{print $0,"addstr";}' input_file

here,

  1. pattern must be same in two regex.
  2. addstr - going to append in the end of line.

Cheers,
Ranga:)

See if this sed fills your requirement

"s#\^main=EXE\^cmd=run script /usr/prog/[Aa-Zz]\{1,5\}_[0-9]\{1,5\}#&.txt#g" file > outfile

It will match a line containing <first part> /usr/prog<any 1 to 5 letters> followed by an underscore and <any 1 to 5 numbers >.

$ sed 's,\^\"$,.txt\^\",g' infile

thanks for the code and its work fine and return what i want..the problem is
I'm using the for do loop so the output will print end of the line multiple .txt
is it any possibility to use "if condition"
for example

if
blah.txt
exit
fi

help...