Hi friends! 🤓 I am on a gnulinux and trying to list all files in the active directory and it’s subdirectories. I then want to pipe the output to “cat”. I want to pipe the output from cat into grep.
Please help! 😅
To answer your og question since it is a valuable tool to know about, xargs.
ls | xargs cat | grep print
Should do what you want. Unless your file names have spaces, then you should probably not use this.
find -print0 | xargs -0 can handle spaces
Edit and you probably want xargs --exec instead of piping after
Note, you almost never have to use cat. Just leaving it out would have been enough to find your file (although find is still better).
When you want to find a string in a file it’s also enough to use
grep string file
instead ofcat file | grep string
. You can even search through multiple files withgrep string file1 file2 file*
and grep will tell you in which file the string was found.Obligatory link to the Useless Use of Cat Awards
I think you can just do
grep print **/*
.ripgrep
does exactly what you wantI just pipe to
more
and filter with /