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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep/awk not getting the message correctly SwapnaNaidu Shell Programming and Scripting 2 11-12-2008 01:56 AM
grep -A switch not working correctly with -m zer0 UNIX for Dummies Questions & Answers 2 06-19-2008 06:26 AM
Grep date from ls -l GenMen Shell Programming and Scripting 1 05-01-2008 09:53 PM
Is grep being used correctly? sai0899 Shell Programming and Scripting 2 04-18-2008 12:03 AM
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
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-09-2009
trezero trezero is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 1
Question How do I grep a Date correctly

I am still a novice at this stuff, but I have searched everywhere and I cant seem to get this working.

I am using a database program that I need to pull information from. The command I am using is the following.

search /project | grep "date -v -1m "+%Y-%m""

This returns no results, however if I break it down it doesnt make sense to me because,

date -v -1m "+%Y-%m""
will return the result of "2009-02"

If I run the command
search /project | grep "2009-02"
I get the results I expect (every file with a creation date or modification date of 2009-02

If I create a variable x=2009-02
then run the command
search /project | grep "$x"
this works and returns all the files created or modified in 2009-02

So why is it that if I set my variable as the date of the previous month using
lastmonth=" date -v -1m "+%Y-%m""
and then run the search with
search /project | grep "$lastmonth"
gives me no results?

Also, FYI, I tried running the whole command together
/search /project | grep " date -v -1m "+%Y-%m""
and still got no results.

Please help. I feel like I've been going in circles on this for 2 days now.

Thanks

-- Jason
  #2 (permalink)  
Old 03-09-2009
Perderabo's Avatar
Perderabo Perderabo is online now Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,100
If you do this:
var=date

echo $var
echo "$var"
you're just going to get the work "date" displayed. To run the date command and use its output, you need to do:
echo $(date)
echo $($var)
if you're using a modern shell. If you're using an antique shell:
echo `date`
echo `$var`

And next time please tell us which shell you're using.
Sponsored Links
Closed Thread

Bookmarks

Tags
date, grep, search, variable

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 10:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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