search in a directory using grep command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting search in a directory using grep command
# 1  
Old 05-18-2005
search in a directory using grep command

Hi,

I want to search files/directories in /temp directory which starts with letter 'a'. How can I do that using grep command.

I can find out like ls -ltr a* but I want to use grep command like ls -ltr | grep ..... like that.

Please help.

Malay
# 2  
Old 05-18-2005
Try

ls -1 | grep "^a"
# 3  
Old 05-21-2005
Quote:
Originally Posted by malaymaru
I can find out like ls -ltr a* but I want to use grep command like ls -ltr | grep ..... like that.
Why? Why launch a grep process unnecessarily?! Unless you have a huge volume of files to sift through which is going to cause shell expansion problems, why create the additional overhead? Smilie

Cheers
ZB
# 4  
Old 05-23-2005
Tools try this

ls -lt|cut -f2 |grep ^a

Chrs
Rahul
# 5  
Old 05-23-2005
Quote:
Originally Posted by rahul123_libra
ls -lt|cut -f2 |grep ^a
???
This will not output anything useful. In fact, it my directory full of files beginning with the letter "a", it produced no output.

If you really want to use grep, then just do....

Code:
ls -1t /some/dir | grep "^a"

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep command to search pattern corresponding to input from user

One more question: I want to grep "COS_12_TM_4 pattern from a file look likes : "COS_12_TM_4" " ];I am taking scan_out as the input from the user. How to search "COS_12_TM_4" in the file which is corresponds to scan_out (12 Replies)
Discussion started by: Preeti Chandra
12 Replies

2. Homework & Coursework Questions

Search email addresses using grep command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Let's say if we have a file with a lot of information. For example: iiadam otterhedgehog kayleigh... (2 Replies)
Discussion started by: ForeignGuy
2 Replies

3. Shell Programming and Scripting

Search file pattern using grep command

I 'm writing a script to search particular strings from log files. The log file contains lines start with *. The file may contain many other lines start with *. I need to search a particular line from my log file. The grep command is working in command line , but when i run my script, Its printing... (7 Replies)
Discussion started by: vinus
7 Replies

4. Linux

How to search multiple word using grep command?

How to search multiple word using grep command for example i want to reserch ANJ001 AA Using ridiculous font, size, and color changes instead of normal space separated text and CODE tags obfuscates what you are trying to do and makes it difficult for volunteers who may want to help you solve... (1 Reply)
Discussion started by: na.dharma
1 Replies

5. Shell Programming and Scripting

Grep command is not search the complete pattern

I am facing a problem while using the grep command in shell script. Actually I have one file (PCF_STARHUB_20130625_1) which contain below records. SH_5.55916.00.00.100029_20130601_0001_NUC.csv.gz|438|3556691115 SH_5.55916.00.00.100029_20130601_0001_Summary.csv.gz|275|3919504621 ... (2 Replies)
Discussion started by: sumit.vedi1988
2 Replies

6. Shell Programming and Scripting

Pattern search using grep command !

Hi, I am trying to do pattern search using grep command. But i donot know what mistake i'm doing. I am not getting the expected Result. could any one please help me out? $ cat b.ksh AasdjfhB 57834B 86234B 472346B I want to print the line which is starting with either A or 8 and... (10 Replies)
Discussion started by: nikesh29
10 Replies

7. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

8. Shell Programming and Scripting

Conditional grep command to search entire file

Let me give you a complete example what I am trying to achieve. 1. Below is the log file structure where I need 2,5 and 14th column of the logs after grepping through the linkId=1ddoic. Log file structure:- abc.com 20120829001415 127.0.0.1 app none11111 sas 0 0 N clk Mozilla/5.0... (3 Replies)
Discussion started by: kmajumder
3 Replies

9. UNIX for Advanced & Expert Users

whats command for search including sub directory ?

What is the command for search the program name from the entire directory (all directories in the unix box, means including sub directories...) (2 Replies)
Discussion started by: gksenthilkumar
2 Replies

10. UNIX for Dummies Questions & Answers

Search / Find / grep command ...

Is there any command, so I can retrieve all the records in a file from the first occurance of a search string, within that file? (4 Replies)
Discussion started by: videsh77
4 Replies
Login or Register to Ask a Question