我尝试过的事情:
awk '
{
if (condition)
{
array[FNR]=$1;
print array[FNR];
df home/user/loc1 home/user/loc2 > file1.txt
}
fi
print array[]
}' /home/user/testfile.txt
我得到的错误:
awk: cmd. line:18: df home/user/loc1 home/user/loc2 > file1.txt
awk: cmd. line:18:
^ syntax error
awk: cmd. line:20: print array[]
awk: cmd. line:20: ^ syntax error
awk: cmd. line:20: fatal: invalid subscript expression
答案 0 :(得分:0)
我相信这就是你要找的东西,
awk '
{
if (condition)
{
array[FNR]=$1;
print array[FNR] # >> file2.txt (use this if you want to print to a file)
system("df home/user/loc1 home/user/loc2") >> file1.txt # Not sure why you want to run df shell command inside awk
}
} END { # after the entire test file is read you can do your calculations below
for (i in array) print array[i];
}' /home/user/testfile.txt