Write a word at 72nd position of a matched line in a file

Hi,

I need to search a file for a pattern,replace some other word and write a word at its 72nd position.

For example,

My name is Mano.Im learning Unix.

I want to search the file in all lines containing the word "Mano".In that matched line,replace the word "Unix" with "Java".And write the string "Line Changed" at its 60th position.

output like,

My name is Mano.Im Learning Java. Line Changed

Kindly help

Not sure what exactly what you want.. for given input following will work

try

$ echo "My name is Mano.Im learning Unix" | awk '/Mano/{gsub("Unix","Java")}1'
My name is Mano.Im learning Java

OR

$ echo "My name is Mano.Im learning Unix" | sed '/Mano/s/Unix/Java/g'
My name is Mano.Im learning Java

OR

$ echo "My name is Mano.Im learning Unix" | perl -pe '/Mano/ && s/Unix/Java/g'
My name is Mano.Im learning Java

Thanks Akshay.

After Finding and replacing, in the same matched line , i want to put a comment,say "Line Changed" , at its nth position .
The output should be,

My name is Mano.Im learning Java Line Changed.

Try

$ echo "My name is Mano.Im learning Unix" | awk '/Mano/{gsub("Unix","Java");printf $0 OFS "Line Changed.\n"}'
My name is Mano.Im learning Java Line Changed.

Hi mano1 n,

Could you please try the following code, this wil help too.

echo "My name is Mano.Im learning Unix" | sed '/Mano/s/Unix/Java Line Changed/g'

It's output will be as follows.

My name is Mano.Im learning Java Line Changed

Thanks,
R. Singh

Not sure why you say pos. 72 in the thread header and 60 in your first post. And, had you used code tags as required by forum rules, your desired output had been clear to all other posters above. Nevertheless, try:

awk '/Mano/  {sub("Unix","Java"); printf "%-59s%s\n", $0, "Line Changed."}' file
My name is Mano.Im learning Java.                          Line Changed.