To remove space-separated words that contain a string, you could do something like:
rpm -qa --qf '%{NAME} ' |
perl -lane 'print join " ", grep {! /google/} @F'
Where:
-lan is the awk mode where the -expression is evaluated for each line of input(s) (-n), split into fields (@F array) à la -awk, with the -line delimiter removed on input and added back on output.
grep {code} @list returns the elements of @list for which the code returns true.
join " " joins the result with spaces.
Or you could do:
rpm -qa --qf '%{NAME}\n' |
grep -v google |
paste -sd ' ' -
That is print a newline delimited list instead of space delimited one so you can use grep to filter it and then join the resulting lines with spaces using paste's -self-paste mode with space as -delimiter.
But if the point is that you want to pass that list as arguments to a command, then you don't need to have a space-delimited list. Unlike in Microsoft OSes, commands are not passed a command line string, they are passed a list of separate arguments, and in any case you'd need to split that list whether it's space-separated or newline-delimited, and the typical operators that do that splitting do it on newline as well as space by default.
cmd -- $(rpm -qa --qf '%{NAME}\n' | grep -v google)
in POSIX-like shells¹, command substitution ($(...) or the archaic form `...`), when left unquoted in list contexts splits the output of the command (trimmed of all trailing newline characters) on characters of $IFS (space, tab, newline (and nul in zsh) by default), and then performs globbing on the result (not in zsh nor fish) so would do what you want as long as package names don't contain space, tabs, nor wildcards (*, ?, [...]).
(
set -o noglob
IFS=$'\n'
cmd -- $(rpm -qa --qf '%{NAME}\n' | grep -v google)
)
Would be more correct in sh implementations as splitting only on newline and disabling the globbing.
In zsh, you can use the f parameter expansion flag to split on newline (aka linefeed) only, would you have packages with space or tab in their name.
cmd -- ${(f)"$(rpm -qa --qf '%{NAME}\n' | grep -v google)"}
(also note the quotes around $(...) to disable the IFS-splitting).
The (t)csh equivalent:
cmd -- "`rpm -qa --qf '%{NAME}\n' | grep -v google`"
(when quoted, `...` splits on newline only, and no globbing is performed)
The rc (and derivatives) equivalent:
cmd -- `{rpm -qa --qf '%{NAME}\n' | grep -v google}
(splits on characters of $ifs, space, tab, newline by default; no globbing)
cmd -- ``('
'){rpm -qa --qf '%{NAME}\n' | grep -v google}
To split on newline only.
Or you can use xargs which splits on blanks² or newline and understands some form of quoting (though not in the same way as in any modern shell):
rpm -qa --qf '%{NAME}\n' | grep -v google | xargs cmd --
Would work as long as package names don't contain blanks, ', " or \ characters.
Note that it also affects the stdin of cmd.
With GNU xargs and a shell with support for Korn-style process-substitution:
xargs -rd '\n' -a <(rpm -qa --qf '%{NAME}\n' | grep -v google) cmd --
- with
-r, it avoids running cmd if the resulting list is empty (unlikely here)
- with
-d '\n', it splits on newline only
xargs will run cmd several times if the list of arguments is larger than execve()'s limit.
- the list is passed as a filename argument to
-a, so stdin is not affected.
¹ or recent versions of fish where they've added support for the Korn/POSIX style of command substitution. The native form of command substitution (but that cannot be used inside quoted strings) there is (...) alone. How it's split has changed a lot along fish history, but nowadays (cmd) or $(cmd) gives you the lines of the output of cmd, even empty ones, regardless of the value of $IFS, but bearing in mind that some of fish builtin commands are handled magically there.
² the list of blank characters varies with the xargs implementation and possibly locale but includes at least space and tab.
xargsor command substitution would split the list into a list of arguments (as you'd want to do on Unix-like systems) whether the items are delimited with space or newline.rpm -qa --qf '%{NAME}\n' | grep -Fv -e google -e font -e kernel | paste -s -?