I would not really do this with sed, as this is not the best tool to work with. A tool awkis my selection tool when someone mentions columns.
cat file | awk '$2 == "qux" { print $1 } $2 != "qux" { print $0 }'
or the simplest form:
cat file | awk '{ if ($2 == "qux") {$2 = ""}; print }'
If you must use sed:
cat file | sed 's/ *qux *$//'
make sure you use the correct empty space (in the example above only spaces are used).
source
share