Visit Our UNIX and Linux User Community


grep/matching help with long listing of directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep/matching help with long listing of directories
# 1  
Old 10-02-2009
grep/matching help with long listing of directories

How do I get this to work?
Code:
cat somefile | grep "-rw-r--r--  1 root  wheel       287 Sep 10 15:12 shells~"

This is the the desired output

Code:
-rw-r--r--  1 root  wheel       287 Sep 10 15:12 shells~

I basically want an exact match of the line I am grepping for, the special characters and spaces are giving me errors. Or is there another method I could use?
# 2  
Old 10-02-2009
Try single quotes in place of double quotes.
# 3  
Old 10-02-2009
Quote:
Originally Posted by methyl
Try single quotes in place of double quotes.
Yea I tried that to no avail, still getting errors.
# 4  
Old 10-02-2009
Quote:
Originally Posted by streetfighter2
How do I get this to work?
Code:
cat somefile | grep "-rw-r--r--  1 root  wheel       287 Sep 10 15:12 shells~"

This is the the desired output

Code:
-rw-r--r--  1 root  wheel       287 Sep 10 15:12 shells~

I basically want an exact match of the line I am grepping for, the special characters and spaces are giving me errors. Or is there another method I could use?
Congratulations, you're the proud recipient of a UUOC Award. Smilie Remember, whenever you write 'cat filename | command' you can almost almost always rewrite this in a simpler way as 'command < filename'.

I'm guessing(since you didn't say) that it's complaining about bad parameters. It thinks your string is a switch since it starts with -. If you want to tell grep that the following option is a parameter and not a switch, you can add -- before it.

Code:
grep -- "-rw-r--r--  1 root  wheel       287 Sep 10 15:12 shells~" < filename


Last edited by Corona688; 10-02-2009 at 03:08 PM..
# 5  
Old 10-02-2009
Thanks Corona688 , I missed the leading hyphen. Now if the OP had posted the error message ...


This should be faster without the inward redirect.

Code:
grep -- "-rw-r--r--  1 root  wheel       287 Sep 10 15:12 shells~" filename

# 6  
Old 10-02-2009
thanks guys!

Previous Thread | Next Thread
Test Your Knowledge in Computers #149
Difficulty: Easy
In a 1999, Dennis Ritchie stated that Linux and the BSD operating systems were a continuation of the basis of the Unix design approach and were Unix derivatives.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Listing a file/directory with 7 letters long

I know that I can use wild cards:ls ???????to list files 7 characters long, but how do i omit the .?! and spaces? Please use CODE tags when displaying sample input, sample output, and code segments. (2 Replies)
Discussion started by: hiya54
2 Replies

2. Shell Programming and Scripting

Shell script to run sql query having a long listing of parameters

Hi, I have a query regarding execution of a sql query having long listing of parameters ..I need to execute this query inside a shell script. The scenario is like.... Suppose I have a file abc.txt that has the card numbers..it could be in thousands.. then I need to fire a query like ... (12 Replies)
Discussion started by: vsachan
12 Replies

3. Shell Programming and Scripting

listing directories and sub directories with time and name options

Hello all! I'm looking to list directories and sub-directories of a path, on this forum I found this command: find $path -type d -exec ls -ld {} \; The issue I have is that with a simple ls, the list is listed by name, and using -t I get it by time. How could I list directories and sub... (5 Replies)
Discussion started by: nomadvisuals
5 Replies

4. UNIX for Dummies Questions & Answers

shell script for long listing of groupnames

Hello, When listing the file systems (using ls -ltr) , if the group names are longer the group name is getting truncated. Can someone help with the script which would display the truncated group name? I appreciate if someone could help in this regard. (3 Replies)
Discussion started by: mike12
3 Replies

5. Solaris

Listing the long groupnames

Hello, When listing the file systems (using ls -ltr) , if the group names are longer the group name is getting truncated. Can someone help with the script which would display the truncated group name? I appreciate if someone could help in this regard. (1 Reply)
Discussion started by: mike12
1 Replies

6. UNIX for Advanced & Expert Users

script regarding listing long group names

Hello, When listing the file systems (using ls -ltr) , if the group names are longer the group name is getting truncated. Can someone help with the script which would display the truncated group name? I appreciate if someone could help in this regard. (1 Reply)
Discussion started by: mike12
1 Replies

7. UNIX for Dummies Questions & Answers

Long listing of files using find command on remote server via SSH

Hi , I am trying to find some files on a remote machine using the find command. >ssh -q atukuri@remotehostname find /home/atukuri/ -name abc.txt /home/atukuri/abc.txt The above command works fine and lists the file, but if I want to do a long listing of files (ls -l) its not working . ... (2 Replies)
Discussion started by: atukuri
2 Replies

8. Shell Programming and Scripting

long process listing with /usr/ucb/ps weird behaves

hello I am trying to run the following script to get the my-progam pid: #!/bin/ksh tt=`/usr/ucb/ps| grep -i $1| grep -v grep | awk '{print $2}'` echo $tt When I run the script I get the more PIDs $./test.sh my-program 12033 15033 15034 Actually my-program's PID is 12033....I... (6 Replies)
Discussion started by: sreeniatbp
6 Replies

9. UNIX for Dummies Questions & Answers

Listing directories and ${1:+$1/}*

Hi I have 2 questions: Q1 - What does ${1:+$1/}* mean? I guess it lists all files in current directory - Could any one explain how this expression works? Q2 - I am trying to list directories only in current path - I know that ls could be used but I thought I'd give find a try. I need to... (5 Replies)
Discussion started by: GMMike
5 Replies

10. UNIX for Dummies Questions & Answers

long listing of files up to a given date

Hi I would like to a long list of files up to a given date. I've tried: ls -al > filelist but this command gives me all the files. I've also have tried the find command: find . -mtime -10 -type f -print > filelist This gives me information on active file within the past 10 days and... (2 Replies)
Discussion started by: rlh
2 Replies

Featured Tech Videos