When I run a command (COMMAND) on one line of my input file (input.txt) I get an associated result where only one line is interesting, always starting by the world phylum.
<This will do the job:
for p in $(<input.txt)
do
(COMMAND $p | grep -w "phylum") || echo "non_assigned"
done >> results.txt
This runs the command and the grep
in a subshell. If the grep
finds 'phylum', the RHS of the ||
is not run; if 'phylum' is not found, the echo
is executed to output a suitable marker.
Notice that the redirection has been moved to after the done
; it might be better to use >
rather than >>
now.
Beware the set option -o pipefail
— if the command can fail, you might need to use set +o pipefail
. However, it is disabled by default, so you'll probably be OK.