Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk system command 3

Status
Not open for further replies.

superstarjpmc

Programmer
Jan 22, 2004
38
US
Hello there,

requriement:

I want to find the file type ( 'file <filename>' ) for all the files in the filesystem.

i used : system(&quot;file &quot;$1) inside a awk construct.

My question is how can I get the output of the system command in a variable

cheers
dj
 
cmd=&quot;file &quot; $1;

cmd | getline cmdOut; close(cmd);

# your output is in cmdOut variable

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
awk '
{

system(&quot;file &quot;$1)

} ' /tmp/host.out


This will produce a o/p like

/tmp/xx.awk: commands text

But I want to capture the o/p in a variable inside the awk program itself.
 
[tt]
{
cmd=&quot;file &quot; $1;
while ( cmd | getline cmdOut ) {
print cmdOut # Proceed result line cmdOut
}
close(cmd);
}
[/tt]

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top