Using shell commands in awk

Hi,

I've searched this site and the wider web and have not found anything (that I can understand..) that helps me.

I've used shell commands in awk fine in the past, the difference is that I want to pass the shell command a field variable within awk from the current input.

A simple example I'm struggling to get working is below:

echo rpm|awk '{"rpm -qc " $1 "|grep etc|getline configfile;print configfile}'

The error I get is:
awk: {"rpm -qc " $1 "|grep etc|getline configfile;print configfile}
awk:                ^ unterminated string
-bash: echo: write error: Broken pipe

I'm using this noddy example just so I can understand how it works before I look at using it properly.

Any guidance would be much appreciated.

echo rpm|awk '{system "rpm -qc " $1 "|grep etc|getline configfile";print configfile}'

What is getline for? awk or shell ?

I've never used the system function before. I've always run the command and used getline to populate a variable with the information, such as:

awk ' BEGIN {"who|wc -l"|getline users;print "Users logged on: " users}'
Users logged on: 2

Try:

awk -v name=rpm 'BEGIN{while("rpm -qc " name "|grep etc"|getline configfile) print configfile}'

or

awk -v name=rpm 'BEGIN{while("rpm -qc " name |getline) if(/etc/)print}'

Of course, this is elaborate, you do not need awk for this as it can be done straight in the shell.

rpm -qc rpm | grep etc