Reputation: 12631
I was writing a sheel scripting to print the 7th column of the output from an executable
get_events -r > f
awk '{print $7}' f > k
while read h
do
fsstat $h
done <k
I need to directly execute the command fsstat which takes the i/p from the o/p derived with the get_events. How to get the command fsstat executed without involving the storage on files(f and h) as above
Upvotes: 1
Views: 41
Reputation: 785731
You can combine this script into one:
while IFS=' ' read -ra arr; do
fsstat "${arr[6]}"
done < <(get_events -r)
< <(get_events -r)
to read from the
output of command get_events -r
array
using read -a
${arr[6]}
which is 7th index since it starts with 0
.Upvotes: 2
Reputation: 75568
get_events -r | awk '{print $7}' | while read h; do
fsstat "$h"
done
Another if you're using bash:
while read h; do
fsstat "$h"
done < <(get_events -r | awk '{print $7}')
And this one would prevent fsstat
from eating up input:
while read -u 4 h; do
fsstat "$h"
done 4< <(get_events -r | awk '{print $7}')
And here's another portable way in which you don't have to use awk
:
get_events -r | while read _ _ _ _ _ _ h _; do
fsstat "$h"
done
Upvotes: 2