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.
$ 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.
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.