Mac open grep file list -
i want search string in files , pipe resulting file list osx's "open" command, opening files contain said string editing in 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, piping list open command fails:
find . -name "*.txt" | xargs grep -l "randomstring" | open i think it's because of "newlines" or "carriage returns" because running:
open ./folder1/file1.txt ./folder1/file2.txt ./folder2/file3.txt ./file4.txt works.
i'm not sure how remove newline characters returned output , pipe open command. need command pipe output through format file list pipe list open command. although newline characters may not problem.
p.s. - don't want create temp file this. open creating .zshrc or .bashrc function.
find . -name "*.txt" | xargs grep -l "randomstring" | xargs open
only keeping open did not work because command open expecting input proper format, not coming stdin pipe. xargs there read line line stdin , feed open. sidenote, xargs have problem filename containing spaces. find, use -print0 option @ end deal that. sample find xargs available in man xargs
Comments
Post a Comment