3 ms·
how do I execute the out put of something like this: grep -i 'pattern' file | awk '{print $5}' | sed 's/^/cmd/g' I end up sending to a file, chmod, then run i
by yogione 14y ago
how do I execute the out put of something like this:
grep -i 'pattern' file | awk '{print $5}' | sed 's/^/cmd/g'
I end up sending to a file, chmod, then run it at the shell.
- badboy 14y agoWrap it in $() to execute. And even if you pipe it into a file, no chmod is required. "sh file" works as it should
- slug 14y agoor use eval ~$ help eval eval: eval [arg ...] Execute arguments as a shell command. Combine ARGs into a single string, use the result as input to the shell, and execute the resulting commands. Exit Status: Returns exit status of command or success if command is null.
- michaelcampbell 14y agoIn bash... $(grep -i 'pattern' file | awk '{print $5}' | sed 's/^/cmd/g') ? Or surround in backticks `command which outputs text you want to run as a command` I prefer $() as they nest better. Or have I misunderstood your question?
- yogione 14y agoThat's it $() works. thanks.
- Domenic_S 14y agoxargs instead of that sed (I assume you're prepending your command to run there). grep -i 'pattern' file | awk '{print $5}' | xargs cmd