Using argument in grep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using argument in grep
# 1  
Old 09-10-2009
Using argument in grep

#!/bin/bash
export var=$1
export path=/ank/desktop
ll -altr | grep $var > tosend.lst


Hi above is the script. but it does not run i gives error regarding usage of grep.


Thanks
ankur
# 2  
Old 09-10-2009
put $var with double quotes as "$var"....but that's what ll in your script ???????
# 3  
Old 09-10-2009
when i execute script

./ tt.sh ank
line6: 11: command not found.

although the tosend.lst is being generated . but no contents in that. ank i have a file named ank in the path used

---------- Post updated at 07:25 AM ---------- Previous update was at 07:06 AM ----------

any suggestions???
# 4  
Old 09-10-2009
Quote:
Originally Posted by ankurk
#!/bin/bash
export var=$1
export path=/ank/desktop
ll -altr | grep $var > tosend.lst


Hi above is the script. but it does not run i gives error regarding usage of grep.


Thanks
ankur
Hi ankurk,

try this....

Code:
#!/bin/bash
var=$1
path=/ank/desktop
echo $var
grep -rw "$var" * > tosend.lst

Not sure what exactly your are looking for ..!
Things will be clear for mates if you can provide sample input and expected output..

Cheers,
Sai

Last edited by reddybs; 09-10-2009 at 12:31 PM.. Reason: added redirection in code
# 5  
Old 09-10-2009
Thanks guys... the only problem was ll ... so i changed it to ls -altr. it worked after using "$var"

Thanks sai... i will try ur method as well

cheers
Ankur
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python script to grep fields and use values from file 1 as argument for another command

Hi Experts, I am working one one python script in version 3.x and 2.6. Need your support to complete it Basically for both commands i have telnet to device and run command and then receiving input File 1 and File 2 I have two commands, need to grep data and output in csv file. Next script/code... (0 Replies)
Discussion started by: as7951
0 Replies

2. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

3. Shell Programming and Scripting

grep : Argument list too long

Hi, i am having some trouble with the below command, can some one suggest me the better way to do it. grep -l 'ReturnCode=1' `find $Log -newer /tmp/Failed.tmp -print | xargs ls -ld | egrep SUB | egrep -ve 'MTP' -ve 'ABC' -ve 'DEF' -ve 'JKL' -ve 'XYZ' | awk '{print $9}'` > $Home1 Its... (2 Replies)
Discussion started by: Prateek007
2 Replies

4. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

5. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

6. UNIX for Dummies Questions & Answers

grep -v with multiple argument

Hi, I want to grep ORA-XXX errors in a file but not ORA-16055: FAL request rejected ORA-16401: archivelog rejected by RFS ORA-16040: ORA-12154 Then I thought of grep -v ORA-16055 ORA-16401 ORA-16040 ORA-12154 myfile that does not work. Any solution ? (other than : grep -v... (1 Reply)
Discussion started by: big123456
1 Replies

7. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

8. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

9. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

10. UNIX for Dummies Questions & Answers

How to find the last argument in a argument line?

How to find the last argument in a argument line? (4 Replies)
Discussion started by: nehagupta2008
4 Replies
Login or Register to Ask a Question