Trouble with grep again :(.. URGENT plss!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble with grep again :(.. URGENT plss!
# 1  
Old 03-16-2006
Data Trouble with grep again :(.. URGENT plss!

Frenz,

I have a file with certain columns from ls -lR which looks something like:

file stemp
----------
lrwxrwxrwx ./temp/s1 -> 2.ksh
lrwxrwxrwx ./temp/s2 -> 3.ksh
lrwxrwxrwx ./temp/subtemp/s3 -> 1.ksh
lrwxrwxrwx ./temp/subtemp/s4 -> 2.ksh
lrwxrwxrwx ./temp/s5 -> nonksh
lrwxrwxrwx ./temp/subtemp/s6 -> nonksh

I'm trying to extract only those lines from this file which are links to files of .ksh extension.

My expression is:
grep "^l*.ksh\>" stemp but this gives me a null output.

Any corrections on the pattern or any more ideas?

I'd like to do it with sed but have no idea how. Can anyone please help?

Thanks a lot,
Sirisha

Last edited by manthasirisha; 03-16-2006 at 06:59 AM.. Reason: typo error
# 2  
Old 03-16-2006
Code:
[/tmp]$ echo "lrwxrwxrwx ./temp/s1 -> 2.ksh
> lrwxrwxrwx ./temp/s2 -> 3.ksh
> lrwxrwxrwx ./temp/subtemp/s3 -> 1.ksh
> lrwxrwxrwx ./temp/subtemp/s4 -> 2.ksh
> lrwxrwxrwx ./temp/s5 -> nonksh
> lrwxrwxrwx ./temp/subtemp/s6 -> nonksh" | grep "\.ksh$"
lrwxrwxrwx ./temp/s1 -> 2.ksh
lrwxrwxrwx ./temp/s2 -> 3.ksh
lrwxrwxrwx ./temp/subtemp/s3 -> 1.ksh
lrwxrwxrwx ./temp/subtemp/s4 -> 2.ksh

# 3  
Old 03-16-2006
Thanks Vino!
Even grep "\.ksh$" stemp worked fine.

Also, can you please tell me how to do the same for multiple extensions.. say i want to extract only those lines of .ksh, .sql and .ini. How can the expression be?

Yet, any idea of why my original expression wouldn't work?

Thanks again!
Sirisha

Last edited by manthasirisha; 03-16-2006 at 07:58 AM.. Reason: additional text
# 4  
Old 03-16-2006
Quote:
Originally Posted by manthasirisha
----------
lrwxrwxrwx ./temp/s1 -> 2.ksh
lrwxrwxrwx ./temp/s2 -> 3.ksh
lrwxrwxrwx ./temp/subtemp/s3 -> 1.ksh
lrwxrwxrwx ./temp/subtemp/s4 -> 2.ksh
lrwxrwxrwx ./temp/s5 -> nonksh
lrwxrwxrwx ./temp/subtemp/s6 -> nonksh


"^l*.ksh\>" but this gives me a null output.
The . in *. means any character, including . itself. If you want to capture the . in its entirety, you need to escape it, like \.

Another thing .* means any character followed by 0 or more characters. So l* means 0 or more occurences of l followed by a single character followed by ksh

In other words your pattern would have caught
Code:
l.ksh
.ksh
ll.ksh
llllllllll.ksh
2ksh
lmksh


Last edited by vino; 03-16-2006 at 08:08 AM..
# 5  
Old 03-16-2006
Another question!

How can the expression be if I have to do the same for multiple file extensions.. say i want to extract only those lines of .ksh, .sql and .ini. ??

Would this work?
grep "[\.ksh][\.ini][\.sql]$" stemp

Please correct me if I am wrong...

Appreciating ur help,
Sirisha
# 6  
Old 03-16-2006
Try this.

Code:
grep -e "\.ksh" -e "\.sql" -e "\.ini" stemp

If you want to condense those into a single statement, look into egrep or "grep -E" option.
# 7  
Old 03-16-2006
Wonderful Vino,

It really helped solve my problem, and that too in a jiffy. Thank you so much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trouble with tail and grep

Good Morning, i ran into some trouble this morning while 'improving' my monitoring stuff. i would like to get a warning when the number of mails sent (outbound) by postfix is above a certain number. so far, so easy. to test that i simply put cat /var/log/mail.info | grep 'to=<' | grep -v -e... (1 Reply)
Discussion started by: Mike
1 Replies

2. UNIX for Beginners Questions & Answers

Grep trouble in Bash

PH=(6H 0 0 JD 9S 0 KD 0) #input from .txt file In the above array, I am trying to get the computer to tell me at what indices the non-zeros are at. I don't understand why this doesn't work... grep -v -b "0" ph.txt > position.txt Isn't grep -v supposed to show non matches in Bash?... (2 Replies)
Discussion started by: cogiz
2 Replies

3. OS X (Apple)

Having trouble creating an alias for grep

Hi, I'm using Mac 10.9.1. I would like to create an alias for grep so that it won't print out messages like "grep: /Users/davea/workspace/myproject/subdir/: Is a directory" all the time. So in my terminal, I opened ~/.profile and entered alias grep='grep -s' However, when I close and... (5 Replies)
Discussion started by: laredotornado
5 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Having trouble with simple grep search

I have a text file (allWords.txt), that I would like to search through. Here is a snippet of what it looks like... a aah aahed aahing aahs aardvark aardvarks aardwolf ab abaci aback abacus abacuses abaft ...... I would like to use the grep search to search, line by line, for... (8 Replies)
Discussion started by: blackvelvet
8 Replies

5. Shell Programming and Scripting

Having a little trouble with grep

I am trying to make a script that has grep finding lines that I get from the cat command, that start with something and end with an argument. I can get the first part, but whenever I try to add on the part that looks at the end of the line too, it stops working. Any ideas why? Here is my script: ... (11 Replies)
Discussion started by: sammythesp3rmy
11 Replies

6. Shell Programming and Scripting

Emergency grep/delete trouble!!!

Hi everyone, thank you so much for reading. I built a user reference page from /etc/password for a class project. Now I need two shell scripts: 1) Add names to the reference page 2) Delete names from the reference page. I know grep -v is involved somehow and some piping but I am super stuck. ... (1 Reply)
Discussion started by: jsmpdx
1 Replies

7. Shell Programming and Scripting

!!VERY URGENT!! Trouble in getting user input, while using under CASE statement in UNIX

i want to get user input like this please tell which option to chose 1. mango 2. tango 3. rango if user chooses mango then it should execute a set of statements and again ask like this what do you want to do 1.add 2.subtract 3.exit when i choose exit it should goto my previous... (1 Reply)
Discussion started by: s.deepak
1 Replies

8. Solaris

Need a booteable Solaris 8 cd PLSS!!!

Hi I need urgently a Solaris 8 , 9 or 10 Booteable. I cant find a booteable cd in sun.com....any help would be appreciated!!! Thx in advance for your help.:) (4 Replies)
Discussion started by: lolos406
4 Replies

9. Shell Programming and Scripting

grep : having trouble with a single quote

Hi, I search for the string below which contains a single quote, some text '/home/myuser in the file myfile.txt as another user with the grep command as follows su - myuser -c "grep 'some text \'/home/myuser' myfile.txt" I also tried using two backslashes su - myuser... (6 Replies)
Discussion started by: cimcmahon
6 Replies

10. Shell Programming and Scripting

URGENT grep question

I want to grep "abc" from "logyy". I want not only the instance of "abc" to return, but the line just above it as well (no matter what it is). :) Can some one please assit me to drive on this (2 Replies)
Discussion started by: NIMISH AGARWAL
2 Replies
Login or Register to Ask a Question