Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: virtual files?
- X-seq: zsh-users 21476
- From: "Benjamin R. Haskell" <zsh@xxxxxxxxxx>
- To: Zsh-Users List <zsh-users@xxxxxxx>
- Subject: Re: virtual files?
- Date: Fri, 22 Apr 2016 01:55:02 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benizi-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=wySx39cmc8fMnHOb7TPBm2x/Q/mgJUigTgfOsjGw5b4=; b=FzkIiLcWUq3zuygZU9X572jCtReXxHWSGsEBw9zEGZc1z2UiJP0+hoGWX8qtwuwhIu B26hki3ALLZPPyltux8gsfA4xI2TjX54ODvPzXVtlNJhlDYLdg7Q8ldkDKGRF/tfXsD0 +n36ZGTHFKuljGQ22D1ZcjjQLNcN9TS6p8SmFw6aj+7A5i2c641+Z8KLmmR0yI2Dm3ZN LASb2Pb7WijErlMeugxUS/n48LXkm2ty5UEK6Cvg7vpp5wMJRE/ZDhMiFU7pUlXK2wGS +jNpmPsdt11URSTfWKfYjXdLeddgG7vX8w+sJoKR3IlO2zILdHkOTR7S90r5N4qkYnbx xJTQ==
- In-reply-to: <87zisneh10.fsf@student.uu.se>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <8760vdrt5y.fsf@student.uu.se> <CAB2RFrTTibd-8FLs5GoGbMiTS2Gk8L8CVq1gC5im_8LmF3F6Zw@mail.gmail.com> <87zisneh10.fsf@student.uu.se>
- Sender: benizi@xxxxxxxxxx
On Thu, Apr 21, 2016 at 12:12 AM, Emanuel Berg <embe8573@xxxxxxxxxxxxx>
wrote:
> "Benjamin R. Haskell" <zsh@xxxxxxxxxx> writes:
>
> > [...]
> > () {
> > local tmp=$1
> > wget -q $link -O $tmp
> > echo -n \$
> > grep \"answer\" $tmp | cut -d \$ -f 2 | cut -d \< -f 1
> > } =(:)
> > }
>
> [...]
>
> Only remark is, if you do all this trouble to get
> clean code, and then name the local "tmp", it is
> almost comical.
I like to think of it as a lingering code smell. Don't need a tmp file
after all. ;-)
[...]
> > awk '/"answer"/' |
>
> awk instead of grep in this context should be strange
> to many who are more familiar with grep, but grep has
> the problem that many like to put colorization to it
> which can screw up parsing. If the configuration
> is in an environmental, I suppose not even giving the
> full path to the binary to bypass an alias would get
> them away. One can supply a specification, of course,
> telling grep not to use colors, but rather than doing
> that, I switched to awk as you suggested.
>
I tend to prefer awk for a few reasons:
1. Whatever I wanted to `grep` usually needs some small amount of
post-processing. (not in this case, but usually scope expands.)
2. It's often one fewer pipe than a `grep ... | cut ...`
3. In a lot of contexts it's nice that it doesn't exit non-zero even if
nothing matches.
4. Its implementations tend to be very consistent (no worries about GNU vs
non-GNU or Linux/other that often arise with other utilities), so it's a
good command to learn.
I also changed the two cut:s for tr, and date +%Y from
> the `one` syntax form into $(another).
>
I strongly favor $(another) due to its nestability.
[...]
> One interesting thing is tho I changed three programs
> out of three used, I don't think this function is
> anything "remote" to the one I originally wrote.
> A small homage to the diversity of the Linux/Unix
> tools, I suppose. But come to think of it there are
> many players in the NHL that score some ~15 goals
> every season, but that doesn't mean they cannot also
> be completely different players, physical aspects as
> well as those of skill and style...
>
I noticed that I'd changed all the tools you used, too. It's also fun to
notice that (maybe?) 5 years ago, I probably would've used Perl for the
whole pipeline, but these days I pretty rarely fall back to it.
--
Best,
Ben
Messages sorted by:
Reverse Date,
Date,
Thread,
Author