The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
grep time and date ayhanne Shell Programming and Scripting 8 01-06-2008 09:12 AM
grep using date format ali560045 Shell Programming and Scripting 4 12-26-2007 08:59 AM
grep using date format ali560045 Shell Programming and Scripting 8 12-11-2007 06:39 PM
grep for date in file scabral Shell Programming and Scripting 2 05-29-2007 12:27 PM
ls -l | grep $date (failing) yongho Shell Programming and Scripting 1 08-01-2005 03:30 PM

Closed Thread
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 05-01-2008
GenMen GenMen is offline
Registered User
  
 

Join Date: May 2008
Posts: 1
Grep date from ls -l

I have a script which required the month and day as the input

ex : ./script <Month> <date>

from this I get the list of files to do further logics. The problem is when I assign these $1 and $2 to variables, and use grep command in the script

ls -l |grep "$1 $2"

it works fine for two digit dates, but for single digit dates, it doesnt work as Unix leaves an additional space in the ls -l list..

How can get this done.
  #2 (permalink)  
Old 05-01-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
* will match any number of the preceding character. Also it's good to match a space after the last value so that you don't find Apr 22 when you are actually searching for Apr 2, for example.

Code:
ls -l |grep " $1  *$2 "
Closed Thread

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 08:24 AM.


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