John Lawrence Aspden John Lawrence Aspden - 6 months ago 26
Bash Question

bash: how do I concatenate the output of two commands so that I can pipe them to a third?

$ hg status


and

$ hg status --ignored


give very similar outputs. I'd like to concatenate them so I can feed them to awk, as if there were an hg status --all (or svn's svn status --no-ignore)

I'm thinking something like:

$ echo "$(hg status)" "$(hg status --ignored)" | awk ' ( $1 == "?" ) || ( $1 == "I") { print $2 }' | xargs rm -r


to make a 'make very clean indeed' command, but it seems to occasionally leave a file behind, perhaps because a newline goes missing or something.

Answer

You can use a subshell:

( hg status; hg status --ignored ) | awk '( $1 == "?" ) || ( $1 == "I") { print $2 }' | xargs rm -r