I want to search for a string in files and pipe the resulting file list to OSX's "open" command, thus opening all files that contain said string for editing in their default editor (aka not vim).
For example, running:
find . -name "*.txt" | xargs grep -l "RANDOMSTRING"
might return:
./folder1/file1.txt
./folder1/file2.txt
./folder2/file3.txt
./file4.txt
however, simply piping this list to the open command fails:
find . -name "*.txt" | xargs grep -l "RANDOMSTRING" | open
I think it's because of the "newlines" or "carriage returns" because running:
open ./folder1/file1.txt ./folder1/file2.txt ./folder2/file3.txt ./file4.txt
works.
I'm just not sure how to remove the newline characters from the returned output and pipe it to the open command. I need another command to pipe the output through that will format the file list properly to then pipe the list to the open command. Although the newline characters may not even be the problem.
P.S. - I DON'T want to create a temp file to do this. I am however open to creating a .zshrc or .bashrc function.