Paste value at specific column using sed

Hi

I want to paste some value at specific column in a file using sed.
say I want to add "Welcome to UNIX" from column 300 onwards in a file using sed.

How to do it .

---------- Post updated at 11:18 AM ---------- Previous update was at 11:09 AM ----------

Adding more information :
I am using this command

sed "s/$/$var1$var2/g" $FILE

However it is appending at the end of each line.
I want to append it from column 300 onwards.

Instead of $ can I specify column from which I want.

 $sed "s/.\{300\}/&Welcome to UNIX/g" FILE

Hi
Thanks for your reply.

I am trying this :

sed "s/.\{300\}/$var1$var2/g" $FILE

However , it is not working.
It is giving error :

sed: Function s/.\{300\}/100200/g cannot be parsed.
I tried like this, 

## Sample file
$ cat a
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

$ cat t.sh

var1=100
var2=200

sed "s/.\{300\}/&$var1$var2/g" a

## see 100200 in output

$sh t.sh
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789010020012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

If in my file data is till 280 column only and I want to add content at 300 column .
Will this still work ?

make clear definition of the word column. column to some may mean fields delimited by some character(s). ie, field 300. Or are you talking about "character position 300 onwards" ?

I mean character position 300 onwards...
And my file is having data only at 280 character position.
I want to add values from 300 character position onwards.

I am trying this :

sed "s/.\{300\}/$var1$var2/g" $FILE

However it is not working.

Well, you can first add 20 spaces at the end of each line (assuming that all the lines are of fixed length of 280 chars each) and then use your sed command to add the text at the end of the line. That would work I guess.

awk '{printf "%-300sWelcome to UNIX\n",$0}' urfile

Thanks for your reply .

But I am looking for something like this :

sed "s/.\{300\}/$var1$var2/g" $FILE

this code is giving error.

I wonder what should be the correct code.

I want to append data at character position 300 when my file is having data at character position lesser than 300.

Any suggestions...

while read -r line
do
 case "${#line}" in
    [012][0-9][0-9] | [0-9][0-9] | [0-9] ) echo "${line}new characters...";;
    * )echo "${line}";;
 esac 
done <"file"

Hi
I couldn't get what are we doing here ???:confused:

What error are you getting?

Function : sed "s/.\{300\}/100200/g" cannot be parsed.

Is it anyway related to the fact that I want to append data at character position 300 when my file is having data at character position lesser than 300.

I mean last character in every line in my file is @ character position less than 300 and I am appending new data @ char position 300 onwards...

Did you have a look at rdcwayx' code?