Operating System - HP-UX
1832928 Members
2339 Online
110048 Solutions
New Discussion

Invoking shell commands from AWK

 
SOLVED
Go to solution
Deepak BS
Occasional Contributor

Invoking shell commands from AWK

Hi,

I have a simple awk script which will process a file and print out some lines. Now, for each of these lines I want to invoke a command, say "sed". Is there a way for doing this in awk?

Cheers,
Deepak
3 REPLIES 3
Tomek Gryszkiewicz
Trusted Contributor
Solution

Re: Invoking shell commands from AWK

From man awk:
system(cmd) Executes cmd and returns its exit status

-Tomek
Deepak BS
Occasional Contributor

Re: Invoking shell commands from AWK

Thats cool.

Thanks Tomek
Alan Turner
Regular Advisor

Re: Invoking shell commands from AWK

Here's a noddy example:


awk '$1 == "here" { system ("echo " S0 " | sed -e s/good/better/" ) }' << {{
no good text
here good text
there good text
{{

(produces "here better text")

Alternatively:

a) pipe the output from awk into sed, which would avoid awk runnng sed on each match
b) do the text selection and manipulation in PERL.