How to add a character at end of line?

Hai,

I have got a small requirement in my script. and i am using bash shell. I need to add a dot (.) for some particular line in a file. Say for example,

$Cat rmfile
1 This is line1
2 This is line2
3 This is line3


O/p should be :
$Cat rmfile
1 This is line1
2 This is line2.   # Here at line number 2nd i need to add DOT.
3 This is line3

Here is what i have tried but didnt work :frowning:

    j=`sed -n $prline'p' $rmfile`    # Here i am taking the line at particular number
    i=`echo $j | sed 's/$/./'`          # here am appending DOT to it and using below #  two operations. One is sed to replace. another is awk. Neither is working

    awk '{if(NR == $a) {print $i >> $rmfile}}'     #using awk
    sed -i 's/"$j"/"$i"/g' $rmfile                            # using sed to replace

Please suggest me the proper way...

Thank you

Try:

printf '2s/$/./\nw\nq'|ed -s rmfile

Or GNU / BSD sed:

sed -i.bak '2s/$/./' file