Unix Programming - awk command

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2006 > awk command





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author awk command
pawan_test

2006-03-21, 5:56 pm

Hi all.,

i am working on script.

I have a file. i type ls -ltr and i get

-rwxrwx--- 1 pavi C2052EX 15 Mar 21 09:50
START.TTN.20060321.095017.ctl_20060321095032

( pls note everything is in 1 line, here it came in 2 lines.)

I have to use awk command and only get the MAR 21 to be displayed in
the out.it is tab delimited.

can anyone help me please how can i do it using awk

thanks
pavi

Pascal Bourguignon

2006-03-21, 5:56 pm

"pawan_test" <sridhara007@gmail.com> writes:

> Hi all.,
>
> i am working on script.
>
> I have a file. i type ls -ltr and i get
>
> -rwxrwx--- 1 pavi C2052EX 15 Mar 21 09:50
> START.TTN.20060321.095017.ctl_20060321095032
>
> ( pls note everything is in 1 line, here it came in 2 lines.)
>
> I have to use awk command and only get the MAR 21 to be displayed in
> the out.it is tab delimited.
>
> can anyone help me please how can i do it using awk


ls -ltr | awk '{printf "%s\t%s\n",$6,$7;}'

Note however that that date field in the output of ls can have
different formats.


--
__Pascal_Bourguignon__ _ Software patents are endangering
() ASCII ribbon against html email (o_ the computer industry all around
/\ 1962:DO20I=1.100 //\ the world http://lpf.ai.mit.edu/
2001:my($f)=`fortune`; V_/ http://petition.eurolinux.org/
Rainer Temme

2006-03-21, 5:56 pm

pawan_test wrote:

> I have a file. i type ls -ltr and i get
> -rwxrwx--- 1 pavi C2052EX 15 Mar 21 09:50
> START.TTN.20060321.095017.ctl_20060321095032


> I have to use awk command and only get the MAR 21 to be displayed in
> the out.it is tab delimited.


How about

ls -ltr | awk '{ printf("%s %s\n",$6,$7); }'

Rainer
pawan_test

2006-03-21, 5:56 pm

Hi Guys.,


thanks for the suggestions. both the suggestions are working.
ls -ltr | awk '{printf "%s\t%s\n",$6,$7;}'
ls -ltr | awk '{ printf("%s %s\n",$6,$7); }'

when i execute the above command it gives me all the values in the
fields 6 and 7.
i am looking in the output to display only march 21. ( i.e today's
date) .
can you please give me a suggestion.

thanks
pavi

Pascal Bourguignon

2006-03-21, 5:56 pm

"pawan_test" <sridhara007@gmail.com> writes:

> Hi Guys.,
>
>
> thanks for the suggestions. both the suggestions are working.
> ls -ltr | awk '{printf "%s\t%s\n",$6,$7;}'
> ls -ltr | awk '{ printf("%s %s\n",$6,$7); }'
>
> when i execute the above command it gives me all the values in the
> fields 6 and 7.
> i am looking in the output to display only march 21. ( i.e today's
> date) .
> can you please give me a suggestion.


Yes. Read:
man awk

--
__Pascal Bourguignon__ http://www.informatimago.com/

PLEASE NOTE: Some quantum physics theories suggest that when the
consumer is not directly observing this product, it may cease to
exist or will exist only in a vague and undetermined state.
Jim Cochrane

2006-03-21, 5:56 pm

On 2006-03-21, pawan_test <sridhara007@gmail.com> wrote:
> Hi Guys.,
>
>
> thanks for the suggestions. both the suggestions are working.
> ls -ltr | awk '{printf "%s\t%s\n",$6,$7;}'
> ls -ltr | awk '{ printf("%s %s\n",$6,$7); }'
>
> when i execute the above command it gives me all the values in the
> fields 6 and 7.
> i am looking in the output to display only march 21. ( i.e today's
> date) .
> can you please give me a suggestion.


Well, that's easy:

echo hi|awk '{ print "Mar\t21" }'

Or, if you want the current date if you run this tomorrow and beyond:

set $(date)
echo hi|awk '{ print "'$2'\t'$3'" }'

:-)

(Point of this satirical post: Providing a good specification for a problem
solution, even a seemingly simple one, is often difficult and requires great
precision. You need more precision in your problem statement if you want
to cut down on the number of repetitions of: "Yes, that does xxx nicely,
but that's not what I asked for - I asked for yyy.")


--

*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
John W. Krahn

2006-03-21, 8:48 pm

pawan_test wrote:
>
> i am working on script.
>
> I have a file. i type ls -ltr and i get
>
> -rwxrwx--- 1 pavi C2052EX 15 Mar 21 09:50
> START.TTN.20060321.095017.ctl_20060321095032
>
> ( pls note everything is in 1 line, here it came in 2 lines.)
>
> I have to use awk command and only get the MAR 21 to be displayed in
> the out.it is tab delimited.
>
> can anyone help me please how can i do it using awk


You can do it in Perl:

perl -MPOSIX -le'print strftime( "%b\t%e", localtime +( stat
"START.TTN.20060321.095017.ctl_20060321095032" )[ 9 ] )'


John
--
use Perl;
program
fulfillment
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com