Mat
Mat

Reputation: 1

Using AWK to treat files

I want to create a batch file with awk, grep or sed that keeps all lines beginning with 'INSERT' and deletes the other lines.

After this, I want to replace a string "change)" by "servicechange)" when the 3rd word in the treated line is "donextsit".

Can someone explain how to do this?

Upvotes: 0

Views: 186

Answers (2)

edgar.holleis
edgar.holleis

Reputation: 4991

sed '
    /^INSERT/ ! d;
    /^ *[^ ]\+ *[^ ]\+ *donextsit / s/change)/servicechange)/g;
' -i file

Edit: Incorporated Jonathan Leffler's suggestions.

Upvotes: 0

ghostdog74
ghostdog74

Reputation: 342373

awk '/INSERT/{ 
    if ($3=="donextsit"){
       gsub("change","servicechange");
       print
    }
}' file

since this is homework, something is still not working..you should find out for yourself

Upvotes: 1

Related Questions