FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 08-20-2008, 10:03 AM
"Dan Track"
 
Default Awk question

Guys,

Just wondering if you could lend me a little hand. Basically I want to
rename a file from log.1 log.2 etc to log.10.36.34. The time stamp
(ignore the date) should be the last written time, so far I've got to
this stage:

stat log | sed -n '/Modify:/p' | awk -F ' ' '{print $3}'

so I get :
11:01:09.000000000

How can I get rid of the leading 0'swithout having to pipe the output
to anotehr awk statement, is it possible to do this withing the
current awk statement?

Thanks
Dan

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 08-20-2008, 10:11 AM
Rui Miguel Silva Seabra
 
Default Awk question

On Wed, Aug 20, 2008 at 11:03:58AM +0100, Dan Track wrote:
> Just wondering if you could lend me a little hand. Basically I want to
> rename a file from log.1 log.2 etc to log.10.36.34. The time stamp
> (ignore the date) should be the last written time, so far I've got to
> this stage:
>
> stat log | sed -n '/Modify:/p' | awk -F ' ' '{print $3}'
>
> so I get :
> 11:01:09.000000000
>
> How can I get rid of the leading 0'swithout having to pipe the output
> to anotehr awk statement, is it possible to do this withing the
> current awk statement?

There simpler solutions but this works:

stat log | awk '/Modify/ { print $3 }' | cut -d . -f 1

--
Wibble.
Today is Boomtime, the 13rd day of Bureaucracy in the YOLD 3174
+ No matter how much you do, you never do enough -- unknown
+ Whatever you do will be insignificant,
| but it is very important that you do it -- Gandhi
+ So let's do it...?

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 08-20-2008, 10:58 AM
Chris G
 
Default Awk question

On Wed, Aug 20, 2008 at 11:03:58AM +0100, Dan Track wrote:
> Guys,
>
> Just wondering if you could lend me a little hand. Basically I want to
> rename a file from log.1 log.2 etc to log.10.36.34. The time stamp
> (ignore the date) should be the last written time, so far I've got to
> this stage:
>
> stat log | sed -n '/Modify:/p' | awk -F ' ' '{print $3}'
>
> so I get :
> 11:01:09.000000000
>
> How can I get rid of the leading 0'swithout having to pipe the output
> to anotehr awk statement, is it possible to do this withing the
> current awk statement?
>
Probably, yes, look at the substr() function.

You don't need the sed in the pipe either I don't think, you could do
this with the pattern matching capabilities of awk, e.g. (not tested) :-

stat log | awk -F ' ' '/Modify:/ {print $3}'

(N.B. I haven't done the substr() bit)

--
Chris Green

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 08-20-2008, 01:20 PM
"Patrick O'Callaghan"
 
Default Awk question

On Wed, 2008-08-20 at 11:03 +0100, Dan Track wrote:
> Guys,
>
> Just wondering if you could lend me a little hand. Basically I want to
> rename a file from log.1 log.2 etc to log.10.36.34. The time stamp
> (ignore the date) should be the last written time, so far I've got to
> this stage:
>
> stat log | sed -n '/Modify:/p' | awk -F ' ' '{print $3}'
>
> so I get :
> 11:01:09.000000000
>
> How can I get rid of the leading 0'swithout having to pipe the output
> to anotehr awk statement, is it possible to do this withing the
> current awk statement?

Use printf instead of print.

poc

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 08-21-2008, 08:14 AM
"Dan Track"
 
Default Awk question

On Wed, Aug 20, 2008 at 11:11 AM, Rui Miguel Silva Seabra <rms@1407.org> wrote:
> On Wed, Aug 20, 2008 at 11:03:58AM +0100, Dan Track wrote:
>> Just wondering if you could lend me a little hand. Basically I want to
>> rename a file from log.1 log.2 etc to log.10.36.34. The time stamp
>> (ignore the date) should be the last written time, so far I've got to
>> this stage:
>>
>> stat log | sed -n '/Modify:/p' | awk -F ' ' '{print $3}'
>>
>> so I get :
>> 11:01:09.000000000
>>
>> How can I get rid of the leading 0'swithout having to pipe the output
>> to anotehr awk statement, is it possible to do this withing the
>> current awk statement?
>
> There simpler solutions but this works:
>
> stat log | awk '/Modify/ { print $3 }' | cut -d . -f 1
>


Hi

I had already changed it to do it the way you mentioned. Guess there's
no way to do a second break within AWK.

Thanks Guys,

Dan

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 08-21-2008, 02:08 PM
"Patrick O'Callaghan"
 
Default Awk question

On Thu, 2008-08-21 at 09:14 +0100, Dan Track wrote:
> On Wed, Aug 20, 2008 at 11:11 AM, Rui Miguel Silva Seabra <rms@1407.org> wrote:
> > On Wed, Aug 20, 2008 at 11:03:58AM +0100, Dan Track wrote:
> >> Just wondering if you could lend me a little hand. Basically I want to
> >> rename a file from log.1 log.2 etc to log.10.36.34. The time stamp
> >> (ignore the date) should be the last written time, so far I've got to
> >> this stage:
> >>
> >> stat log | sed -n '/Modify:/p' | awk -F ' ' '{print $3}'
> >>
> >> so I get :
> >> 11:01:09.000000000
> >>
> >> How can I get rid of the leading 0'swithout having to pipe the output
> >> to anotehr awk statement, is it possible to do this withing the
> >> current awk statement?
> >
> > There simpler solutions but this works:
> >
> > stat log | awk '/Modify/ { print $3 }' | cut -d . -f 1
> >
>
>
> Hi
>
> I had already changed it to do it the way you mentioned. Guess there's
> no way to do a second break within AWK.

As I said before, use printf:

stat log | awk '/Modify/ { printf "%.8s
", $3 }'

poc

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 08-21-2008, 03:17 PM
Roger Heflin
 
Default Awk question

Dan Track wrote:

On Wed, Aug 20, 2008 at 11:11 AM, Rui Miguel Silva Seabra <rms@1407.org> wrote:

On Wed, Aug 20, 2008 at 11:03:58AM +0100, Dan Track wrote:

Just wondering if you could lend me a little hand. Basically I want to
rename a file from log.1 log.2 etc to log.10.36.34. The time stamp
(ignore the date) should be the last written time, so far I've got to
this stage:

stat log | sed -n '/Modify:/p' | awk -F ' ' '{print $3}'

so I get :
11:01:09.000000000

How can I get rid of the leading 0'swithout having to pipe the output
to anotehr awk statement, is it possible to do this withing the
current awk statement?

There simpler solutions but this works:

stat log | awk '/Modify/ { print $3 }' | cut -d . -f 1




Hi

I had already changed it to do it the way you mentioned. Guess there's
no way to do a second break within AWK.

Thanks Guys,

Dan


It's trivial, you need to use the split function.

stat log | awk '/Modify/ { split($3,parts,".") ;print parts[1] }'

Roger

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 08-21-2008, 10:03 PM
"NiftyFedora Mitch"
 
Default Awk question

On Thu, Aug 21, 2008 at 8:17 AM, Roger Heflin <rogerheflin@gmail.com> wrote:
> Dan Track wrote:
>> On Wed, Aug 20, 2008 at 11:11 AM, Rui Miguel Silva Seabra <rms@1407.org>
>> wrote:
>>> On Wed, Aug 20, 2008 at 11:03:58AM +0100, Dan Track wrote:
>>>>
>>>> Just wondering if you could lend me a little hand. Basically I want to
>>>> rename a file from log.1 log.2 etc to log.10.36.34. The time stamp
>>>> (ignore the date) should be the last written time, so far I've got to
>>>> this stage:
>>>>
>>>> stat log | sed -n '/Modify:/p' | awk -F ' ' '{print $3}'
>>>>
>>>> so I get :
>>>> 11:01:09.000000000
>>>>
>>>> How can I get rid of the leading 0'swithout having to pipe the output
>>>> to anotehr awk statement, is it possible to do this withing the
>>>> current awk statement?
>>>
>>> There simpler solutions but this works:
>>>
>>> stat log | awk '/Modify/ { print $3 }' | cut -d . -f 1
>>>
>>
>>
>> Hi
>>
>> I had already changed it to do it the way you mentioned. Guess there's
>> no way to do a second break within AWK.
>>
>> Thanks Guys,
>>
>> Dan
>>
> It's trivial, you need to use the split function.
>
> stat log | awk '/Modify/ { split($3,parts,".") ;print parts[1] }'
>
>

Tinkering with FS may be worth a look too:

stat log | awk 'BEGIN { FS = "[ .]" }; /Modify/ { print $3; print $0 }'

--
NiftyFedora
T o m M i t c h e l l

--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 

Thread Tools




All times are GMT. The time now is 04:31 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org