Passing an argument using alias to piped command

Hi.
I'm trying to do a "simple" thing.

grep -rls grepped_exp path | xgs

where xgs is an alias to something like:

xargs gvim -o -c ":g/grepped_exp"

now the problem is that I want to pass the "grepped_exp" to the piped alias.

I was able to do something like what I want without the alias.

grep -rls grepped_exp path | xargs gvim -o -c ":g/\!:2"

the !:2 contained the second argument. but it doesn't work with the alias.

would be happy to try anything.
Thanks !

Welcome to the forum.

It would help if you could become more specific in your description above:

  • Is the grepped_exp the same in both cases? Is it a variable? A constant?
  • What is the context of that command line?
  • Were it feasible to define the alias just before its usage?

Hi. Thanks for the VERY quick reply. AWESOME !

so, grepped_exp is just my way of saying it's the same expression. it's not a variable.

the purpose of the code (thought it was clear from itself) is to grep an expression in a dir. and open gvim with split windows and search for/highlight that expression in gvim.

meaning, for example: grepping "Linux". finding 2 results. opening gvim and splitting the window to the two result files, and highlighting "Linux" in them.

the only missing piece of the puzzle is - how do I get the 3rd argument from the command before the pipe, when after the pipe, I'm using an alias.

and one last thing, I don't think of a way to define the alias right before the command executes - that wouldn't be efficient. I want an alias I can remember.

thanks again !

Not sure I clearly understood the concept. If it's in a script, why use an alias and not write it down using variables?
How about declaring the entire line as a shell function?

1 Like

It's not in a script.

what exactly isn't clear about the concept ? I want to grep in files, and open the results in gvim and automatically highlight the grepped expression.

I would be happy to hear of ideas. the one I have in my mind is the one I wrote. using alias.