&3" } }' 1>(awk '{print $0"positive"}') 3>(awk '{[print $0"zer" /> &3" } }' 1>(awk '{print $0"positive"}') 3>(awk '{[print $0"zer" /> &3" } }' 1>(awk '{print $0"positive"}') 3>(awk '{[print $0"zer"/>

process multiple file descriptors from 1 command into multiple commands

38 views Asked by At

I would like to do:

cat a.txt |\
awk '{
  if ($1>0) {
    print $0
    } else {
    print $0 | "cat 1>&3" 
    }
}' 1>(awk '{print $0"positive"}') 3>(awk '{[print $0"zero or negative"}')

The idea is that I want to process both outputs separately from the same command.

Is that possible? How? Is that NOT recommended?

Thank you!

1

There are 1 answers

1
Diego Torres Milano On
awk '$1 > 0 {print $0"positive"}' <a.txt >p.txt &  # process A
awk '$1 < 0 {print $0"negative"}' <a.txt >n.txt &  # process B

2 processes and the file is read twice and it's probably buffered. Your example would contain the same number of reads but 3 processes.