Re: [OT] Awk question

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

 



On Thu, Aug 21, 2008 at 8:17 AM, Roger Heflin <rogerheflin@xxxxxxxxx> wrote:
> Dan Track wrote:
>> On Wed, Aug 20, 2008 at 11:11 AM, Rui Miguel Silva Seabra <rms@xxxxxxxx>
>> 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 = "[ \t.]" }; /Modify/ { print $3; print $0 }'

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

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

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux