[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with Grep and date

From: Matthew Woehlke
Subject: Re: Help with Grep and date
Date: Fri, 21 Nov 2008 12:39:43 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20080723 Fedora/ Thunderbird/ Mnenhy/

omega_grey wrote:
Don't I feel like a dork. No wonder why I couldn't find anything. Awk you
say. Will look into it but someone else has suggested I use PERL for this.

Perl would probably work also. grep is for finding strings, it doesn't manipulate them. sed/awk do both, sed is mostly for string/regex replacements, awk is more of a programming language (and also tends to work more with fields, where sed is more line-based). Perl is a flat-out programming language, though somewhat similar to awk in that it has easy input handling (compared to e.g. C/C++).

Hmm... if you have *just* the string "12/01/08" (meaning Jan 12), you can convert it with 'date' like: echo "12/01/08" | sed 's,([0-9]+)/([0-9]+)/([0-9]+),\2/\1/\3,' | xargs -n 1 date '+%Y-%m-%d' -d

...which has the advantage of understanding the input as an actual date. Replace the 'echo' with anything generating "#/#/#" dates, one per line. You should be able to do something similar with times. ('date -d' might be locale-dependent, or I might be wrong about your month/day order; if so, omit the sed part of the pipe.)

Please do not quote my e-mail address unobfuscated in message bodies.
Time is an illusion. Lunchtime doubly so. -- Ford Prefect (Douglas Adams' HHGttG)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]