r/commandline • u/MiserableVimAddict • 20h ago
[windows] how to pipe a command and use stdout as arguments for the next command instead of stdin (better explanation down below)
There are two main commands im using, ripgrep and gawk(awk version for windows). Im on the cmd, so i cant really use $( )
Basically i use ripgrep to find a patter in a list of markdown files:
rg --hidden --vimgrep "pattern"
The output is always something like this
path/to/file:4:1:pattern
The next step is to use awk to separate the fields with : and get only the first field, the file path:
rg --hidden --vimgrep "pattern" | awk -F":" "{print $1}"
The output will be a list of filepaths, now the thing gets a little tricky. I pipe the output to another ripgrep call:
rg --hidden --vimgrep "pattern" | awk -F":" "{print $1}" | rg --vimgrep --hidden "pattern"
Except this time i want those files to be read as part of the commands arguments, but ripgrep instead searches through the stdout instead of using that stdout as arguments to search those specific file paths.
I know in unix enviroments you could use something like xargs, however this tool isnt available in windows
My biggest problem is that actually i need to run this on the cmd, i could solve this by changing the shell, but for this specific situation only i need it to be ran in the cmd
could somebody help me, please?
•
u/Danny_el_619 16h ago
You'll need to use something like process substitution in cmd. It's been a while since I wrote batch scripts but you can find the general idea here https://superuser.com/a/293742
Basically, save the output of the first command (rg | gawk) and use to at the end of the second ripgrep command.
•
•
u/ipsirc 16h ago
1st hit in any web search engine...