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 > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 05-17-2011, 02:34 PM
Pandu Poluan
 
Default is a nice "place" :-D

On 2011-05-17, Alex Schuster <wonko@wonkology.org> wrote:
> Juan Diego Tascón writes:
>
>> I have always wondered if there is a way to do awk '{ print $1}' using
>> only builtin bash functions when you only have a one line string
>
> str="one two five"
>
> # remove all from the first blank on, but will not work with
> # other whitespace
> echo ${str%% *}
>
> or
>
> # set $1, $2, $3, ... to words of $str
> set $str
> echo $1
>
> or
>
> # create array holding one word per element
> strarr=( $str )
> echo $strarr (or echo ${strarr[0]})
>
> Wonko
>
>

How about this:

str="one two three"
read word etc <<< "$str"
echo $word

(not tested, though)

--
Pandu E Poluan - IT Optimizer
My website: http://pandu.poluan.info/
 
Old 05-17-2011, 05:38 PM
Stroller
 
Default is a nice "place" :-D

On 17/5/2011, at 11:43am, Pandu Poluan wrote:
> On 2011-05-17, Neil Bothwick <neil@digimed.co.uk> wrote:
>> On Tue, 17 May 2011 01:33:39 +0200, Alan McKinnon wrote:
>>
>>> grep "GET /Tmp/Linux/G" | /var/log/apache2/access_log | grep-v <myip> |
>>> awk '{print $1}' | sort | uniq | wc
>>>
>> ...
>> awk does pattern matching, o you can ditch the grep stage and use
>>
>> awk '! /myip/ {print $1}'
>> ...
>
> Meh, me forgetting what an awk snippet do? Never!
>
> sed ... now that's a wholly different story :-P

Not addressed at you, specifically, but it rather seems like sed & awk are much under-appreciated these days. I'd guess that this may be due to the changing nature of *nix users, but they seem to have "gone out of fashion". Aside from sed's simple replace, I have certainly never learned to do anything useful with them.

Stroller.
 
Old 05-18-2011, 10:17 AM
Neil Bothwick
 
Default is a nice "place" :-D

On Tue, 17 May 2011 18:38:33 +0100, Stroller wrote:

> Not addressed at you, specifically, but it rather seems like sed & awk
> are much under-appreciated these days. I'd guess that this may be due
> to the changing nature of *nix users, but they seem to have "gone out
> of fashion". Aside from sed's simple replace, I have certainly never
> learned to do anything useful with them.

They both have a steep initial learning curve, which leads to their
adoption being put off. I put awk in the same category as screen, one of
those programs that you hear people going on about for years, but always
manage to put off trying them. Once you do try them, you use them for
everything but slicing bread.


--
Neil Bothwick

Hors d'oeuvres: 3 sandwiches cut into 40 pieces.
 
Old 05-18-2011, 07:03 PM
Alan McKinnon
 
Default is a nice "place" :-D

Apparently, though unproven, at 12:17 on Wednesday 18 May 2011, Neil Bothwick
did opine thusly:

> On Tue, 17 May 2011 18:38:33 +0100, Stroller wrote:
> > Not addressed at you, specifically, but it rather seems like sed & awk
> > are much under-appreciated these days. I'd guess that this may be due
> > to the changing nature of *nix users, but they seem to have "gone out
> > of fashion". Aside from sed's simple replace, I have certainly never
> > learned to do anything useful with them.
>
> They both have a steep initial learning curve, which leads to their
> adoption being put off. I put awk in the same category as screen, one of
> those programs that you hear people going on about for years, but always
> manage to put off trying them. Once you do try them, you use them for
> everything but slicing bread.


Add bash to that list.

Have you read the full man page for the bloody thing?

No wonder most folk stop at launching it after login



--
alan dot mckinnon at gmail dot com
 
Old 05-18-2011, 08:04 PM
Neil Bothwick
 
Default is a nice "place" :-D

On Wed, 18 May 2011 21:03:47 +0200, Alan McKinnon wrote:

> > They both have a steep initial learning curve, which leads to their
> > adoption being put off. I put awk in the same category as screen, one
> > of those programs that you hear people going on about for years, but
> > always manage to put off trying them. Once you do try them, you use
> > them for everything but slicing bread.

> Add bash to that list.
>
> Have you read the full man page for the bloody thing?

It's better than the zsh man page, which is split into several pages.
That sounds like a good idea, and it would have been if there had been
some sort of index so you knew which page to look on.


--
Neil Bothwick

Top Oxymorons Number 46: Found missing
 
Old 05-18-2011, 08:15 PM
Alan Mackenzie
 
Default is a nice "place" :-D

Hi, Alan.

On Wed, May 18, 2011 at 09:03:47PM +0200, Alan McKinnon wrote:
> Apparently, though unproven, at 12:17 on Wednesday 18 May 2011, Neil Bothwick
> did opine thusly:

> > On Tue, 17 May 2011 18:38:33 +0100, Stroller wrote:
> > > Not addressed at you, specifically, but it rather seems like sed &
> > > awk are much under-appreciated these days. I'd guess that this may
> > > be due to the changing nature of *nix users, but they seem to have
> > > "gone out of fashion". Aside from sed's simple replace, I have
> > > certainly never learned to do anything useful with them.

> > They both have a steep initial learning curve, which leads to their
> > adoption being put off. I put awk in the same category as screen, one
> > of those programs that you hear people going on about for years, but
> > always manage to put off trying them. Once you do try them, you use
> > them for everything but slicing bread.


> Add bash to that list.

> Have you read the full man page for the bloody thing?

You're not meant to read that man page through from beginning to end.
Anybody who could learn bash that way would be superhuman.
Unfortunately, the info pages for bash are not well organised. So
beginners have to learn from books, many of which are not good.

And bash is about the most disorganised, arbitrary language around, full
of crazy little quirks and odd sytaxes. And I love it. ;-)

> No wonder most folk stop at launching it after login

> --
> alan dot mckinnon at gmail dot com

--
Alan Mackenzie (Nuremberg, Germany).
 
Old 05-18-2011, 08:28 PM
Alan McKinnon
 
Default is a nice "place" :-D

Apparently, though unproven, at 22:15 on Wednesday 18 May 2011, Alan Mackenzie
did opine thusly:

> Hi, Alan.
>
> On Wed, May 18, 2011 at 09:03:47PM +0200, Alan McKinnon wrote:
> > Apparently, though unproven, at 12:17 on Wednesday 18 May 2011, Neil
> > Bothwick
> >
> > did opine thusly:
> > > On Tue, 17 May 2011 18:38:33 +0100, Stroller wrote:
> > > > Not addressed at you, specifically, but it rather seems like sed &
> > > > awk are much under-appreciated these days. I'd guess that this may
> > > > be due to the changing nature of *nix users, but they seem to have
> > > > "gone out of fashion". Aside from sed's simple replace, I have
> > > > certainly never learned to do anything useful with them.
> > >
> > > They both have a steep initial learning curve, which leads to their
> > > adoption being put off. I put awk in the same category as screen, one
> > > of those programs that you hear people going on about for years, but
> > > always manage to put off trying them. Once you do try them, you use
> > > them for everything but slicing bread.
> >
> > Add bash to that list.
> >
> > Have you read the full man page for the bloody thing?
>
> You're not meant to read that man page through from beginning to end.

Um, I did ....

> Anybody who could learn bash that way would be superhuman.

I doubt I learned much though. I even took the effort to reformat it as an OOo
doc so I could find stuff and give it to others.

It was an interesting exercise, not necessary an interesting *learning*
exercise


> Unfortunately, the info pages for bash are not well organised. So
> beginners have to learn from books, many of which are not good.
>
> And bash is about the most disorganised, arbitrary language around, full
> of crazy little quirks and odd sytaxes. And I love it. ;-)

The difference between bash and perl?

Perl was inspired by a linguist, who at least puts his foot down at the truly
crazy suggestions. Bash has no such thing.


--
alan dot mckinnon at gmail dot com
 
Old 05-19-2011, 07:01 PM
"Walter Dnes"
 
Default is a nice "place" :-D

On Wed, May 18, 2011 at 10:28:55PM +0200, Alan McKinnon wrote

> The difference between bash and perl?
>
> Perl was inspired by a linguist, who at least puts his foot down at
> the truly crazy suggestions. Bash has no such thing.

Perl is a bloated mediocre operating system, complete with repo (CPAN).
But it lacks a lightweight extraction/reporting language. BTW, the most
powerful little-known gem in bash is that you can open filehandles to do
sequential reads and writes, just like in BASIC. For examples, see...
http://blogmag.net/blog/read/48/File_descriptors_in_shell

--
Walter Dnes <waltdnes@waltdnes.org>
 

Thread Tools




All times are GMT. The time now is 08:12 AM.

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