The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
long process listing with /usr/ucb/ps weird behaves sreeniatbp Shell Programming and Scripting 6 06-10-2009 08:07 AM
listing directories alone bbala Shell Programming and Scripting 2 08-03-2008 05:15 AM
listing of directories with / at end...without ls -F vasanthan UNIX for Dummies Questions & Answers 10 04-16-2008 05:34 AM
Listing directories and ${1:+$1/}* GMMike UNIX for Dummies Questions & Answers 5 01-24-2005 09:38 PM
long listing of files up to a given date rlh UNIX for Dummies Questions & Answers 2 10-27-2000 10:43 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-02-2009
streetfighter2 streetfighter2 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 21
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 (permalink)  
Old 10-02-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184
Try single quotes in place of double quotes.
  #3 (permalink)  
Old 10-02-2009
streetfighter2 streetfighter2 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 21
Quote:
Originally Posted by methyl View Post
Try single quotes in place of double quotes.
Yea I tried that to no avail, still getting errors.
  #4 (permalink)  
Old 10-02-2009
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,972
Quote:
Originally Posted by streetfighter2 View Post
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. 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 02:08 PM..
Bits Awarded / Charged to Corona688 for this Post
Date User Comment Amount
10-02-2009 thegeek Nice 500
  #5 (permalink)  
Old 10-02-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184
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 (permalink)  
Old 10-02-2009
streetfighter2 streetfighter2 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 21
thanks guys!
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0