problem with scripting fundamentals ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem with scripting fundamentals ?
# 1  
Old 04-14-2009
problem with scripting fundamentals ?

why this two loops are not listing same files ?

Code:
for pkg in `ls | grep ".rpm"`
    do
       echo $pkg
    done




Code:
for pkg in `ls | grep "*.rpm"`
    do
       echo $pkg
    done


Last edited by Yogesh Sawant; 04-14-2009 at 06:18 AM.. Reason: added code tags
# 2  
Old 04-14-2009
Could be because
Quote:
.... grep "*.rpm"`
does not make much sense in terms of Regular Expressions. When using grep, you use Regular Expressions, not shell wildcards.

Try this instead:
Code:
.... grep ".*\.rpm"`

With shell metacharacters like * you specify "any amount or none of any type of character".
In Regular Expressions you write the same with ".*" which means
Code:
.     Any single character of any type
*     Any amount of the previous character

Since the dot is a special character in the Regular Expressions, you have to escape it with a backslash when you want it being recognized and not substituted.

Also you could just leave the grep out and do something like "ls *.rpm".

Last edited by zaxxon; 04-14-2009 at 07:38 AM.. Reason: repaired the quote ;)
# 3  
Old 04-14-2009
the first useless use of grep we noticed this year
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

scripting problem

Hi I am doing scripting using EXPECT module. I have successfully created the code through which i can login automatically #!/usr/bin/expect spawn ssh 127.0.0.1 expect "abc@127.0.0.1's password:" send "xyz\r" now i want to create directory #!/usr/bin/expect spawn ssh... (0 Replies)
Discussion started by: esumiba
0 Replies

2. UNIX for Dummies Questions & Answers

scripting problem

HI -rw-r--r-- 1 synapse synapse 5242816 Jan 14 22:02 SMSCLOG.25 -rw-r--r-- 1 synapse synapse 1224138 Jan 14 22:14 SMSCLOG.26 below is the file which are generated after every 10 mins i am trynig do scripting in which latest generated file get cta and give ouput I use the below code ... (1 Reply)
Discussion started by: esumiba
1 Replies

3. Shell Programming and Scripting

Scripting problem

I have one table contains the last field is gender and it is entered in small letter ,i would like to convert to caps after checking the field? eg: eno ename loc gender 1 a ch f 2 b hy M 3 c hy m 4 d ... (1 Reply)
Discussion started by: mrbinoy
1 Replies

4. Shell Programming and Scripting

Scripting Problem

Hello guys, I am a newbie to Shell Scripting. I have an issue. My requirement is to search a pattern in a file and then replace it with another pattern. Please note that I have thousands of files having the same pattern and I have to replace it running a script. I have created a script as shown... (4 Replies)
Discussion started by: mahesh_raghu
4 Replies

5. Shell Programming and Scripting

scripting problem

I am trying to write a script that tells us whether the permissions for two files, whose names should be given as arguments to the script, are identical. And if the permissions for the two files are identical, have to output the common permission field. or else output each filename, followed by... (0 Replies)
Discussion started by: manojrsb
0 Replies

6. UNIX for Advanced & Expert Users

scripting problem

hI I m very new to unix ,... I m facing an issue I have to search though a list of directorys, find all .gz files which are older than 7 days and delete that ,,, Any one knows a single command to do this .. Thnks in advance BInu (3 Replies)
Discussion started by: msbinu
3 Replies

7. Shell Programming and Scripting

scripting problem

Sorry everyone, i was able to fix it (0 Replies)
Discussion started by: bebop1111116
0 Replies

8. UNIX for Dummies Questions & Answers

UNIX Fundamentals - Training

Does anyone know of some companies in the United States, preferably close to Utah that teach a crash course like for a week on UNIX fundamentals? I have looked everywhere on the net for such places, but have yet to find such a company. Thank you in advance. (1 Reply)
Discussion started by: quintak
1 Replies
Login or Register to Ask a Question