Existe-t-il un script / programme / utilitaire déjà disponible pour le besoin suivant de manière optimisée?
someCommand | tee >(grep "pattern" > LinesWhichMatch) | grep -v "pattern" > LinesWhichDoesNotMatch
Vous pourriez utiliser awk
pour cela.
command | awk '{ if (/pattern/) { print > "match" } else { print > "nomatch" } }'
Voici un exemple sed
:
Remarque: la command sed de w
remplace un file existant chaque fois que le script est exécuté, mais seulement si cette command d'écriture particulière est déclenchée; d'où la rm
rm -f file-{yes,not} sed -ne '/pattern/bY; w file-not' -e 'b; :Y; w file-yes' file
Vous pouvez append des files dans awk:
awk '{if (/pattern/) print >>"matched"; else print >>"unmatched"; }
ou plus court:
awk '{print >>(/pattern/?"matched":"unmatched")}'