Problem with one awk script

Hi ,

I am having a file having the contents like this
file1
#####################
kite kshitij jolly admire in the wing
and tell me the secret behind
opus 123 and the right of the track

#########################

I have to write one awk script to substitue some values with other

Like I want to substitute "kite" with "holy river" and
123 with "when time comes"

Just see this script

#!/bin/awk -f
BEGIN {
while (( getline line < "./file1") > 0 ) {
if ( line ~ /kite/ ) {
#print line
sub ( /line/, "holy river" , ./file1)

}
}
}

But this script is actually not working
can anyone helps in this regards

Thanks

Kshitij Kulshreshtha

eg

awk '{gsub("kite","word")}{print}' file

play with it, to suit your needs

Hi ,

I tried this but it is not writing to the file1
It is just printing the substitution on the screen
one more requirement is there
The script should serach the "kite" word in the file1 and add additional words to the kite like
kite "flying is a good experience" : Concanetation kind of thing

Please help in this regards

Thanks
Kshitij

And alternatively:

$
$ cat file1
kite kshitij jolly admire in the wing
and tell me the secret behind
opus 123 and the right of the track
$
$ sed -e 's/kite/holy river/g' -e 's/123/when time comes/g' file1
holy river kshitij jolly admire in the wing
and tell me the secret behind
opus when time comes and the right of the track
$
$

tyler_durden

awk doesn't modify the file . you have to redirect to another file, and rename it back to original. i believe you know how to do that. if you want "concatenation", just add the word "kite" next to the new work in the second argument to gsub().

Hi

Thanks for your previous post :

file1 :

POINT AND TPIN 123 GETS LAST
POINT2 GOING TO ONE DAY AFTER

The awk scrip should search the word "POINT2" And at the end of the Line POINT2 GOING TO ONE DAY AFTER it should add the words HEROS GONNA FIGHT

file1 contents should be like this

POINT AND TPIN 123 GETS LAST
POINT2 GOING TO ONE DAY AFTER HEROS GONNA FIGHT

Thanks and Regards
Kshitij

awk '/^POINT2/{$0=$0 " HEROS GONNA FIGHT"}1' file

Regards