No need for a for
loop, use xargs
:
xargs -a my_file -d '
' grep -h -w string
Note #1: I added the -h
option (GNU extension) so that the filenames are not added by grep
in the output (like in your command).
Note #2: since you are using Linux and Bash, I'm assuming GNU xargs
. If your xargs
does not understand the -a
option, then use this instead:
< my_file xargs -d '
' grep -h -w string
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…