You are rite when you use it for only one field. But awk is more powerful than
cut. I just gave you an example to do that.
You can create a query and send it to mysql even without further script.
who | awk '{ printf "insert into table(username, time) values (%s,
%s-%s-2008)\n",$1,$3,$4}'
Scott <[EMAIL PROTECTED]> wrote: On Tue, Jan 15,
2008 at 07:37:54PM -0800, Varghees Samraj wrote:
> you can use awk command to format the output from who
> for eg,
>
> who | awk '{ printf "%s\n",$1}'
>
> use man for more info about awk
>
> use for loop to iterate thru the entries
>
Don't make it needlessly complex. :)
who |awk '{print $1}' will give the same result.
Or, probably easier to type, at least for me
who |cut -d ' ' -f 1
Quick explanation, if you're not familiar with the commands. Varghees
is trying to format the output for you, but in this case, where you're
just getting a name, it shouldn't be necessary. (Not that his way is
bad or wrong, but as a lazy man, I feel my way is more
efficient--Varghee's would be better if the expected output was going to
be more complex.)
awk '{print $1}' just means print the first field of output. By
default, awk uses a white space as delineator.
Cut will often do the same thing if you just need one field. With cut
the -d stands for what you're using as delineator--in this case, white
space, which has to be enclosed in single quotes, hence, d ' '. (Note
that is a quote, a space and another quote. -f is for field, so in this
case we're using white space to separate the fields and we're printing
the first field. In a case like this, where it's relatively simple, I
prefer cut simply because I tend to mistype curly braces. (The {} of
awk.)
All of this goes to prove the adage that in Unix (or Unix like systems)
there's always more than one way to do. The corollary of course, is that
someone will think your way is wrong. :)
--
Scott Robbins
PGP keyID EB3467D6
( 1B48 077D 66F6 9DB0 FDC2 A409 FA54 EB34 67D6 )
gpg --keyserver pgp.mit.edu --recv-keys EB3467D6
Buffy: I told you. I said end of the world. And you're like,
'Pooh-pooh, Southern California, pooh-pooh.'
Giles: I'm so very sorry. My contrition completely dwarfs the
impending apocalypse.
---------------------------------
Never miss a thing. Make Yahoo your homepage.
[Non-text portions of this message have been removed]
To unsubscribe from this list, please email [EMAIL PROTECTED] & you will be
removed.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/LINUX_Newbies/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/LINUX_Newbies/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/