Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Are there some concise awk regexps for matching the things like this: 1,370 2015/01/10 18:21:28?

8 views
Skip to first unread message

Hongyi Zhao

unread,
Apr 11, 2015, 7:44:15 PM4/11/15
to
Hi all,

I want to use awk regexps to match the file size and the date-time
written in following form:

1,370 2015/01/10 18:21:28

I've tried some forms but all of them are cumbersome and I've digged into
the google for it and find also some cumbersome forms.

So, are there some concise awk regexps for matching the things like this:
1,370 2015/01/10 18:21:28?

Regards
--
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.

Barry Margolin

unread,
Apr 11, 2015, 9:07:59 PM4/11/15
to
In article <mgcbkc$lcs$3...@aspen.stu.neva.ru>,
Hongyi Zhao <hongy...@gmail.com> wrote:

> Hi all,
>
> I want to use awk regexps to match the file size and the date-time
> written in following form:
>
> 1,370 2015/01/10 18:21:28
>
> I've tried some forms but all of them are cumbersome and I've digged into
> the google for it and find also some cumbersome forms.
>
> So, are there some concise awk regexps for matching the things like this:
> 1,370 2015/01/10 18:21:28?
>

Something like this?

^[0-9,]+ [0-9]{4}/[0-9]{2}/[0-9]{2} ([0-9]{2}:){2}[0-9]{2}$

Unfortunately, awk doesn't use \d for digits, so you have to use the
more verbose [0-9] throughout.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Kaz Kylheku

unread,
Apr 11, 2015, 9:41:57 PM4/11/15
to
On 2015-04-11, Hongyi Zhao <hongy...@gmail.com> wrote:
> Hi all,
>
> I want to use awk regexps to match the file size and the date-time
> written in following form:
>
> 1,370 2015/01/10 18:21:28

$ echo "1,370 2015/01/10 18:21:28" | txr -B -c '@num @year/@month/@day @hour:@minute:@second' -
num="1,370"
year="2015"
month="01"
day="10"
hour="18"
minute="21"
second="28"

Hongyi Zhao

unread,
Apr 11, 2015, 10:00:35 PM4/11/15
to
On Sun, 12 Apr 2015 01:41:51 +0000, Kaz Kylheku wrote:

> $ echo "1,370 2015/01/10 18:21:28" | txr -B -c '@num @year/@month/@day
> @hour:@minute:@second' -
> num="1,370"
> year="2015"
> month="01"
> day="10"
> hour="18"
> minute="21"
> second="28"

What's the txr used here, I don't have it on my box:

werner@debian:~$ echo "1,370 2015/01/10 18:21:28" | txr -B -c '@num @year/
@month/@day @hour:@minute:@second' -
bash: txr: command not found

Kenny McCormack

unread,
Apr 11, 2015, 10:04:13 PM4/11/15
to
In article <mgcjk0$6j8$1...@aspen.stu.neva.ru>,
Hongyi Zhao <hongy...@gmail.com> wrote:
>On Sun, 12 Apr 2015 01:41:51 +0000, Kaz Kylheku wrote:
>
>> $ echo "1,370 2015/01/10 18:21:28" | txr -B -c '@num @year/@month/@day
>> @hour:@minute:@second' -
>> num="1,370"
>> year="2015"
>> month="01"
>> day="10"
>> hour="18"
>> minute="21"
>> second="28"
>
>What's the txr used here, I don't have it on my box:
>
>werner@debian:~$ echo "1,370 2015/01/10 18:21:28" | txr -B -c '@num @year/
>@month/@day @hour:@minute:@second' -
>bash: txr: command not found

GIYF!

http://www.nongnu.org/txr/

--
"I have a simple philosophy. Fill what's empty. Empty what's full. And
scratch where it itches."

Alice Roosevelt Longworth

Thomas 'PointedEars' Lahn

unread,
Apr 12, 2015, 6:55:55 AM4/12/15
to
Barry Margolin wrote:

> Unfortunately, awk doesn't use \d for digits, so you have to use the
> more verbose [0-9] throughout.

You can also use the more verbose [:digit:] with LC_COLLATE=C ;-)

--
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
0 new messages