JimR
JimR

Reputation: 513

tee to 2 blocks of code?

I am trying to use the tee command on Solaris to route output of 1 command to 2 different steams each of which comprises multiple statements. Here is the snippet of what I coded, but does not work. This iteration throws errors about unexpected end of files. If I change the > to | it throws an error Syntax Error near unexpected token do.

todaydir=/some/path
baselen=${#todaydir}

grep sometext $todaydir/somefiles*

while read iline
tee
>(
# this is the first block
do ojob=${iline:$baselen+1:8}
   echo 'some text here' $ojob
done  > firstoutfile
)
>(
# this is the 2nd block
do ojob=${iline:$baselen+1:8}
   echo 'ls -l '$todaydir'/'$ojob'*'
done  > secondoutfile
)

Suggestions?

Upvotes: 0

Views: 112

Answers (2)

jwodder
jwodder

Reputation: 57590

The "while" should begin (and end) inside each >( ... ) substitution, not outside. Thus, I believe what you want is:

todaydir=/some/path
baselen=${#todaydir}

grep sometext $todaydir/somefiles* | tee >(
   # this is the first block
   while read iline
   do ojob=${iline:$baselen+1:8}
      echo 'some text here' $ojob
   done  > firstoutfile
  ) >(
   # this is the 2nd block
   while read iline
   do ojob=${iline:$baselen+1:8}
      echo 'ls -l '$todaydir'/'$ojob'*'
   done  > secondoutfile
  )

Upvotes: 1

creechy
creechy

Reputation: 405

I don't think the tee command will do that. The tee command will write stdin to one or more files as well as spit it back out to stdout. Plus I'm not sure the shell can fork off two sub-processes in the command pipeline like you are trying. You'd probably be better off to use something like Perl to fork off a couple of sub-process and write stdin to each.

Upvotes: 0

Related Questions