Passing an argument using alias to piped command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing an argument using alias to piped command
# 1  
Old 12-28-2016
Passing an argument using alias to piped command

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

Code:
grep -rls grepped_exp path | xgs

where xgs is an alias to something like:
Code:
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.
Code:
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 !


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 12-28-2016 at 05:06 PM.. Reason: Added CODE tags.
# 2  
Old 12-28-2016
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?
# 3  
Old 12-28-2016
more details

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 !
# 4  
Old 12-29-2016
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?
This User Gave Thanks to RudiC For This Post:
# 5  
Old 12-29-2016
Quote:
Originally Posted by RudiC
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?
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passing resulted string name of a gzipped file as an argument to another piped tool

Hi, I have a .pcap.gz file and I would like to initially gzip it and then pass the resulting .pcap filename as an argument to a piped tool; the right-hand tool is not standardized linux tool but a custom one that strictly requires the string name of a given .pcap file in order for the pcap file... (2 Replies)
Discussion started by: amarn
2 Replies

2. Shell Programming and Scripting

Passing an argument to cut command

Can we pass an argument to cut command as below Suppose cut command is used in for or while loop and we need to pass the incremental counter cut -f$i Here $i is an argument. Like wise it has to come cut -f1 cut -f2 Where i=1,2,3,.... (1 Reply)
Discussion started by: bashamsc
1 Replies

3. Shell Programming and Scripting

Passing argument on find command

Hi, I'm trying to pass the variable in the find command like below a=log.20111114 find /apps/file3_logs/env3/ -name '$a' -exec ls -lrt {} \; but it's not working thanks in advance. Regards Thelak (3 Replies)
Discussion started by: ajithbe
3 Replies

4. Programming

Passing argument to command in C

Hello all, New to C and I'm trying to write a program which can run a unix command. Would like to have the option of giving the user the ability to enter arguments e.g for "ls" be able to run "ls -l". I would appreciate any help. Thanks #include <stdio.h> #include <unistd.h> #include... (3 Replies)
Discussion started by: effizy
3 Replies

5. UNIX for Dummies Questions & Answers

Passing command line argument between shell's

Hi, I am facing a problem to pass command line arguments that looks like <script name> aa bb "cc" dd "ee" I want to pass all 5 elements include the " (brackets). when I print the @ARGV the " disappear. I hope I explain myself Regards, Ziv (4 Replies)
Discussion started by: zivsegal
4 Replies

6. Shell Programming and Scripting

Need Help with the argument passing Through Command line

$$$$$ (5 Replies)
Discussion started by: asirohi
5 Replies

7. Shell Programming and Scripting

passing argument from Cshelll to awk command

Hi all I have got a file digits.data containing the following data 1 3 4 2 4 9 7 3 1 7 3 10 I am writing a script that will pass an argument from C-shell to nawk command. But it seems the values in the nawk comman does not get set. the program does not print no values out. Here is the... (1 Reply)
Discussion started by: ganiel24
1 Replies

8. UNIX for Dummies Questions & Answers

Using * when passing argument to alias

I have some folders with this structure: /data/me/a123xxx Where "xxx" is some changing series of letters, and "123" changes so folders might look like: /data/me/a123xxx /data/me/a234ysd /data/me/a534sds etc. The numbers are what matter to me (they identify the folder), so I created an... (7 Replies)
Discussion started by: ramparts
7 Replies

9. Shell Programming and Scripting

passing a command line argument

I have a shell script which does the encryption of a file where i am passing the file name as a command line argument,but later on the script waits on the screen to enter Y or N what is the command i should be using on the shell script #!/bin/bash -x outfilename=file.out echo... (8 Replies)
Discussion started by: rudoraj
8 Replies

10. Shell Programming and Scripting

Passing the command line argument in a variable

Hi, I am new to unix. Is their a way to pass the output of the line below to a variable var1. ls -1t | head -1. I am trying something like var1=ls -1t | head -1, but I get error. Situation is: I get file everyday through FTP in my unix box. I have to write a script that picks up first... (1 Reply)
Discussion started by: rkumar28
1 Replies
Login or Register to Ask a Question