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