If the size of the output is not too large to fit in memory, and you do not need the wc and sort commands to work in parallel for performance reasons, here's a fairly simple solution:
output=$(awk '$13 ~ /type/ {print $15}' filename.txt; echo a) printf "%s" "${output%a}" | sort -u printf "%s" "${output%a}" | wc -l
This difficulty with optional a is that the awk command can print several empty lines at the end of the input, which will be broken by the $() construct. You can easily choose which of sort or wc should be displayed first.
Here you can work with any POSIX shell (ash, bash, ksh, zsh, ...), but only on systems with /dev/fd (which includes reasonably recent Linux, * BSD and Solaris). Like Walterโs similar construction using the simpler method available in bash, ksh93, and zsh , the wc output and the sort output can be mixed.
{ awk '$13 ~ /type/ {print $15}' filename.txt | tee /dev/fd3 | wc -l } 3>&1 1>&3 | sort -u
If both of you have to deal with an intermediate output that does not fit comfortably into memory and does not want the output of the two commands to be mixed, I do not think that there is an easy way in the POSIX shell, although it should be done using ksh or zsh coprocesses.
source share