zsh-users
 help / color / mirror / code / Atom feed
* Segregating a Global Alias
@ 2014-03-24 14:43 zzapper
  2014-03-24 17:22 ` Bart Schaefer
  0 siblings, 1 reply; 15+ messages in thread
From: zzapper @ 2014-03-24 14:43 UTC (permalink / raw)
  To: zsh-users

Hi
I want to create an output file based on the name of the input file however 
the input file is foung using a Global alis NF

perl -ne 's/(<\/\w+>)/$1\n/g; print' < NF > {NF}.txt     ### Doesn't work

where
alias -g NF='*~vssver.scc(.om[1])'

Solutions, alternatives?

-- 
zzapper
https://twitter.com/dailyzshtip


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Segregating a Global Alias
  2014-03-24 14:43 Segregating a Global Alias zzapper
@ 2014-03-24 17:22 ` Bart Schaefer
  2014-03-24 17:34   ` zzapper
  0 siblings, 1 reply; 15+ messages in thread
From: Bart Schaefer @ 2014-03-24 17:22 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 204 bytes --]

On Mar 24, 2014 7:46 AM, "zzapper" <david@rayninfo.co.uk> wrote:
>
> perl -ne 's/(<\/\w+>)/$1\n/g; print' < NF > {NF}.txt     ### Doesn't work

(){ perl -ne 's/(<\/\w+>)/$1\n/g; print' < $1 > $1.txt } NF

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Segregating a Global Alias
  2014-03-24 17:22 ` Bart Schaefer
@ 2014-03-24 17:34   ` zzapper
  2014-03-24 17:47     ` zzapper
  0 siblings, 1 reply; 15+ messages in thread
From: zzapper @ 2014-03-24 17:34 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer <schaefer@brasslantern.com> wrote in
news:CAH+w=7baCBR0KK+Uvhu8D53CPsVNvq4YSVsrbb35H1ReCHQZAA@mail.gmail.com: 


> 
> (){ perl -ne 's/(<\/\w+>)/$1\n/g; print' < $1 > $1.txt } NF
> 
inspired by this

for f in NF ; perl -ne 's/(<\/\w+>)/$1\n/g; print' < $f > $f.txt



-- 
zzapper
https://twitter.com/dailyzshtip


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Segregating a Global Alias
  2014-03-24 17:34   ` zzapper
@ 2014-03-24 17:47     ` zzapper
  2014-03-24 18:04       ` Re[2]: " Manuel Presnitz
                         ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: zzapper @ 2014-03-24 17:47 UTC (permalink / raw)
  To: zsh-users

zzapper <david@rayninfo.co.uk> wrote in 
news:XnsA2FAB2C8DE4F8davidrayninfocouk@80.91.229.13:

> Bart Schaefer <schaefer@brasslantern.com> wrote in
> news:CAH+w=7baCBR0KK+Uvhu8D53CPsVNvq4YSVsrbb35H1ReCHQZAA@mail.gmail.com: 
> 
> 
>> 
>> (){ perl -ne 's/(<\/\w+>)/$1\n/g; print' < $1 > $1.txt } NF
>> 
> inspired by this
> 
> for f in NF ; perl -ne 's/(<\/\w+>)/$1\n/g; print' < $f > $f.txt
> 
> 
> 
BTW this is perl one liner to put each XML tag on a newline. The input file 
is 10mb and perl takes just seconds, i gave up trying to do this with vim 
(-None) .

But can anyone else trump Bart's or my attempt?


-- 
zzapper
https://twitter.com/dailyzshtip


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re[2]: Segregating a Global Alias
  2014-03-24 17:47     ` zzapper
@ 2014-03-24 18:04       ` Manuel Presnitz
  2014-03-25 12:28         ` zzapper
  2014-03-24 18:11       ` Paul Johnson
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 15+ messages in thread
From: Manuel Presnitz @ 2014-03-24 18:04 UTC (permalink / raw)
  To: zsh-users

zzapper wrote:
> perl -ne 's/(<\/\w+>)/$1\n/g; print' < NF > {NF}.txt     ### Doesn't
> work
> (...)
> But can anyone else trump Bart's or my attempt?

This doesn't look very sophisticated, but seems to work -- and is rather close to your original approach:

perl -ne 's/(<\/\w+>)/$1\n/g; print' < NF > $(print NF).txt

---Manuel.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Segregating a Global Alias
  2014-03-24 17:47     ` zzapper
  2014-03-24 18:04       ` Re[2]: " Manuel Presnitz
@ 2014-03-24 18:11       ` Paul Johnson
  2014-03-24 18:19       ` 'whence' anomaly Ray Andrews
  2014-03-24 22:36       ` Segregating a Global Alias Bart Schaefer
  3 siblings, 0 replies; 15+ messages in thread
From: Paul Johnson @ 2014-03-24 18:11 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

On Mon, Mar 24, 2014 at 05:47:57PM +0000, zzapper wrote:
> zzapper <david@rayninfo.co.uk> wrote in 
> news:XnsA2FAB2C8DE4F8davidrayninfocouk@80.91.229.13:
> 
> > Bart Schaefer <schaefer@brasslantern.com> wrote in
> > news:CAH+w=7baCBR0KK+Uvhu8D53CPsVNvq4YSVsrbb35H1ReCHQZAA@mail.gmail.com: 
> > 
> >> 
> >> (){ perl -ne 's/(<\/\w+>)/$1\n/g; print' < $1 > $1.txt } NF
> >> 
> > inspired by this
> > 
> > for f in NF ; perl -ne 's/(<\/\w+>)/$1\n/g; print' < $f > $f.txt
> > 
> BTW this is perl one liner to put each XML tag on a newline. The input file 
> is 10mb and perl takes just seconds, i gave up trying to do this with vim 
> (-None) .
> 
> But can anyone else trump Bart's or my attempt?

$ perl -pi.orig -e 's|</\w+>(?!\n)\K|\n|g' NF

perhaps?

-- 
Paul Johnson - paul@pjcj.net
http://www.pjcj.net


^ permalink raw reply	[flat|nested] 15+ messages in thread

* 'whence' anomaly.
  2014-03-24 17:47     ` zzapper
  2014-03-24 18:04       ` Re[2]: " Manuel Presnitz
  2014-03-24 18:11       ` Paul Johnson
@ 2014-03-24 18:19       ` Ray Andrews
  2014-03-24 22:48         ` Bart Schaefer
  2014-03-24 22:36       ` Segregating a Global Alias Bart Schaefer
  3 siblings, 1 reply; 15+ messages in thread
From: Ray Andrews @ 2014-03-24 18:19 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 291 bytes --]

All,

What causes this:

>     $ whence -m mplayer
>
>     $ whence mplayer
>     /usr/bin/mplayer
>
>     $ whence -m mplayer
>     /usr/bin/mplayer

I know I should have quoted the first time, but it seems strange that I 
didn't have to quote the third time.
Is this a bug or a feature?



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Segregating a Global Alias
  2014-03-24 17:47     ` zzapper
                         ` (2 preceding siblings ...)
  2014-03-24 18:19       ` 'whence' anomaly Ray Andrews
@ 2014-03-24 22:36       ` Bart Schaefer
  2014-03-25  1:56         ` Bart Schaefer
  3 siblings, 1 reply; 15+ messages in thread
From: Bart Schaefer @ 2014-03-24 22:36 UTC (permalink / raw)
  To: zsh-users

On Mar 24,  5:47pm, zzapper wrote:
} Subject: Re: Segregating a Global Alias
}
} zzapper <david@rayninfo.co.uk> wrote in 
} news:XnsA2FAB2C8DE4F8davidrayninfocouk@80.91.229.13:
} 
} > for f in NF ; perl -ne 's/(<\/\w+>)/$1\n/g; print' < $f > $f.txt

That's fine, but it creates a variable $f that hangs around after the
command is finished.

} BTW this is perl one liner to put each XML tag on a newline.
} 
} But can anyone else trump Bart's or my attempt?

Do it entirely in perl?

perl -pe '$. == 1 && open STDOUT,"> $ARGV.txt"; s/(<\/\w+>)/$1\n/g' NF

That'll work for a whole list of files just like the "for" loop.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: 'whence' anomaly.
  2014-03-24 18:19       ` 'whence' anomaly Ray Andrews
@ 2014-03-24 22:48         ` Bart Schaefer
  2014-03-25  3:10           ` Ray Andrews
  0 siblings, 1 reply; 15+ messages in thread
From: Bart Schaefer @ 2014-03-24 22:48 UTC (permalink / raw)
  To: zsh-users

On Mar 24, 11:19am, Ray Andrews wrote:
}
} What causes this:
} 
} >     $ whence -m mplayer
} >
} >     $ whence mplayer
} >     /usr/bin/mplayer
} >
} >     $ whence -m mplayer
} >     /usr/bin/mplayer

I guess you could think of it as both/either a bug and/or a feature ...

"whence -m" searches, but does not populate, the command hash table.
Thus if the NO_HASH_CMDS option is set, "whence -m" does not work
at all. [*]

"whence" populates the hash table as a side-effect of searching $PATH,
presuming HASH_CMDS is set; but it might not fully populate the table
if HASH_DIRS is set, so "whence -m" of a different command from later
in the $PATH might still fail.

[*] Except that the CORRECT option also relies on the hash table, so
if that is set, as soon as anything might need correcting, the table
gets filled, and "whence -m" will start working again.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Segregating a Global Alias
  2014-03-24 22:36       ` Segregating a Global Alias Bart Schaefer
@ 2014-03-25  1:56         ` Bart Schaefer
  2014-03-25 14:07           ` zzapper
  0 siblings, 1 reply; 15+ messages in thread
From: Bart Schaefer @ 2014-03-25  1:56 UTC (permalink / raw)
  To: zsh-users

On Mar 24,  3:36pm, Bart Schaefer wrote:
}
} perl -pe '$. == 1 && open STDOUT,"> $ARGV.txt"; s/(<\/\w+>)/$1\n/g' NF
} 
} That'll work for a whole list of files just like the "for" loop.

Phil reminds me off-list that $. is not automatically reset when the
value of $ARGV changes, so for multiple files you actually need:

perl -pe '$. == 1 && open STDOUT,"> $ARGV.txt";
         s/(<\/\w+>)/$1\n/g;
         close ARGV if eof;' NF

which might make this answer less appealing.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: 'whence' anomaly.
  2014-03-24 22:48         ` Bart Schaefer
@ 2014-03-25  3:10           ` Ray Andrews
  2014-03-25  6:25             ` Bart Schaefer
  0 siblings, 1 reply; 15+ messages in thread
From: Ray Andrews @ 2014-03-25  3:10 UTC (permalink / raw)
  To: zsh-users

On 03/24/2014 03:48 PM, Bart Schaefer wrote:
> On Mar 24, 11:19am, Ray Andrews wrote:
> }
> } What causes this:
> }
> } >     $ whence -m mplayer
> } >
> } >     $ whence mplayer
> } >     /usr/bin/mplayer
> } >
> } >     $ whence -m mplayer
> } >     /usr/bin/mplayer
>
> I guess you could think of it as both/either a bug and/or a feature ...
>
> "whence -m" searches, but does not populate, the command hash table.
> Thus if the NO_HASH_CMDS option is set, "whence -m" does not work
> at all. [*]
>
> "whence" populates the hash table as a side-effect of searching $PATH,
> presuming HASH_CMDS is set; but it might not fully populate the table
> if HASH_DIRS is set, so "whence -m" of a different command from later
> in the $PATH might still fail.
>
> [*] Except that the CORRECT option also relies on the hash table, so
> if that is set, as soon as anything might need correcting, the table
> gets filled, and "whence -m" will start working again.
>
Yikes, more ifs buts and maybes. Is there some way to get a reliable 
result? AFAICT, none of the
options you mention are set here (that's from scanning the output of  " 
$ set "). Should I always make a
double call?: " $ whence mplayer; whence -m "mplayer" ? Set some option?


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: 'whence' anomaly.
  2014-03-25  3:10           ` Ray Andrews
@ 2014-03-25  6:25             ` Bart Schaefer
  2014-03-25 15:32               ` Ray Andrews
  0 siblings, 1 reply; 15+ messages in thread
From: Bart Schaefer @ 2014-03-25  6:25 UTC (permalink / raw)
  To: zsh-users

On Mar 24,  8:10pm, Ray Andrews wrote:
} Subject: Re: 'whence' anomaly.
}
} On 03/24/2014 03:48 PM, Bart Schaefer wrote:
} >
} > "whence -m" searches, but does not populate, the command hash table.

Hmm, I seem to be wrong about that.  I just double-checked the code
(which I didn't bother to do before) and there is a call there to fill
the command hash table.

Furthermore, I can't reproduce Ray's original example now, though I'm 
pretty certain I did at least once.

} > Thus if the NO_HASH_CMDS option is set, "whence -m" does not work
} > at all. [*]

And this is only partly true. :-(  You have to both set NO_HASH_CMDS
_and_ erase the hash table with e.g. 'unhash -m \*' to break this,
otherwise the aforementioned code in whence fills the table regardless
of NO_HASH_CMDS.

So I apologize for the red herrings.

} Yikes, more ifs buts and maybes. Is there some way to get a reliable 
} result?

Based on what I just (re)discovered, it seems necessary to go out of
the way to get an UNreliable result.  What are the circumstances in
which you get nothing from 'whence -m', again?


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Re[2]: Segregating a Global Alias
  2014-03-24 18:04       ` Re[2]: " Manuel Presnitz
@ 2014-03-25 12:28         ` zzapper
  0 siblings, 0 replies; 15+ messages in thread
From: zzapper @ 2014-03-25 12:28 UTC (permalink / raw)
  To: zsh-users

"Manuel Presnitz" <mpy@gmx.net> wrote in
news:201403241904030744.002438FA@localhost: 


> 
> This doesn't look very sophisticated, but seems to work -- and is
> rather close to your original approach: 
> 
> perl -ne 's/(<\/\w+>)/$1\n/g; print' < NF > $(print NF).txt
> 
> ---Manuel.

Manuel yes this demonstrates how to  append to the result of Global Alias

cat NF > $(print NF).txt



-- 
zzapper
https://twitter.com/dailyzshtip

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Segregating a Global Alias
  2014-03-25  1:56         ` Bart Schaefer
@ 2014-03-25 14:07           ` zzapper
  0 siblings, 0 replies; 15+ messages in thread
From: zzapper @ 2014-03-25 14:07 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer <schaefer@brasslantern.com> wrote in news:140324185656.ZM4923
> 
> Phil reminds me off-list that $. is not automatically reset when the
> value of $ARGV changes, so for multiple files you actually need:
> 
> perl -pe '$. == 1 && open STDOUT,"> $ARGV.txt";
>          s/(<\/\w+>)/$1\n/g;
>          close ARGV if eof;' NF
> 
> which might make this answer less appealing.
> 
LOL



-- 
zzapper
https://twitter.com/dailyzshtip

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: 'whence' anomaly.
  2014-03-25  6:25             ` Bart Schaefer
@ 2014-03-25 15:32               ` Ray Andrews
  0 siblings, 0 replies; 15+ messages in thread
From: Ray Andrews @ 2014-03-25 15:32 UTC (permalink / raw)
  To: zsh-users

On 03/24/2014 11:25 PM, Bart Schaefer wrote:
> Based on what I just (re)discovered, it seems necessary to go out of
> the way to get an UNreliable result.  What are the circumstances in
> which you get nothing from 'whence -m', again?
Well, it's a rare thing here too, that's the first time I noticed it, 
however, it may have happened
before but I just took it as an honest 'not found' result, so I can't be 
positive about this. I haven't
been able to duplicate it today either, but it certainly happened twice 
here yesterday, once
to notice it, then once again for the cut and paste of the result in my 
post to the list. Like some
quantum experiments, it might not happen at all if you are looking ;-)


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-03-25 15:32 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-24 14:43 Segregating a Global Alias zzapper
2014-03-24 17:22 ` Bart Schaefer
2014-03-24 17:34   ` zzapper
2014-03-24 17:47     ` zzapper
2014-03-24 18:04       ` Re[2]: " Manuel Presnitz
2014-03-25 12:28         ` zzapper
2014-03-24 18:11       ` Paul Johnson
2014-03-24 18:19       ` 'whence' anomaly Ray Andrews
2014-03-24 22:48         ` Bart Schaefer
2014-03-25  3:10           ` Ray Andrews
2014-03-25  6:25             ` Bart Schaefer
2014-03-25 15:32               ` Ray Andrews
2014-03-24 22:36       ` Segregating a Global Alias Bart Schaefer
2014-03-25  1:56         ` Bart Schaefer
2014-03-25 14:07           ` zzapper

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).