zsh-users
 help / color / mirror / code / Atom feed
* executing commands in directories containing specific files
@ 2014-02-12  0:11 Leonardo Barbosa
  2014-02-12  0:35 ` Jan Larres
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Leonardo Barbosa @ 2014-02-12  0:11 UTC (permalink / raw)
  To: zsh-users

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

All,

I'd like to find TeX files (find $HOME -type f -name '*.tex'). Let's say i
have found files a.tex, b.tex, and c.tex. Now, i wanna remove a.aux, b.aux,
c.aux. What's the best way of doing that?

Cheers

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

* Re: executing commands in directories containing specific files
  2014-02-12  0:11 executing commands in directories containing specific files Leonardo Barbosa
@ 2014-02-12  0:35 ` Jan Larres
  2014-02-12  1:17   ` Philip Dexter
  2014-02-12  1:53 ` Chris Johnson
  2014-02-12  5:13 ` Bart Schaefer
  2 siblings, 1 reply; 9+ messages in thread
From: Jan Larres @ 2014-02-12  0:35 UTC (permalink / raw)
  To: zsh-users

On 12/02/14 13:11, Leonardo Barbosa wrote:
> I'd like to find TeX files (find $HOME -type f -name '*.tex'). Let's say i
> have found files a.tex, b.tex, and c.tex. Now, i wanna remove a.aux, b.aux,
> c.aux. What's the best way of doing that?

find $HOME -type f -name '*.tex' -exec rm {} \;

Jan


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

* Re: executing commands in directories containing specific files
  2014-02-12  0:35 ` Jan Larres
@ 2014-02-12  1:17   ` Philip Dexter
  2014-02-12  2:17     ` Jan Larres
  0 siblings, 1 reply; 9+ messages in thread
From: Philip Dexter @ 2014-02-12  1:17 UTC (permalink / raw)
  To: zsh-users

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

On Tue, Feb 11, 2014 at 7:35 PM, Jan Larres <jan@majutsushi.net> wrote:

> On 12/02/14 13:11, Leonardo Barbosa wrote:
> > I'd like to find TeX files (find $HOME -type f -name '*.tex'). Let's say
> i
> > have found files a.tex, b.tex, and c.tex. Now, i wanna remove a.aux,
> b.aux,
> > c.aux. What's the best way of doing that?
>
> find $HOME -type f -name '*.tex' -exec rm {} \;
>
>
That won't get the aux files

I would use

for f in $HOME/**/*.tex; do rm $f; rm ${f:r}.aux; done

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

* Re: executing commands in directories containing specific files
  2014-02-12  0:11 executing commands in directories containing specific files Leonardo Barbosa
  2014-02-12  0:35 ` Jan Larres
@ 2014-02-12  1:53 ` Chris Johnson
  2014-02-12  5:13 ` Bart Schaefer
  2 siblings, 0 replies; 9+ messages in thread
From: Chris Johnson @ 2014-02-12  1:53 UTC (permalink / raw)
  To: zsh-users

Leonardo Barbosa sent me the following 0.3K:

> I'd like to find TeX files (find $HOME -type f -name '*.tex'). Let's say i
> have found files a.tex, b.tex, and c.tex. Now, i wanna remove a.aux, b.aux,
> c.aux. What's the best way of doing that?

There's probably a way to combine the glob and the expansion that I don't know about, but you could do this:

  texs=(*.tex) && rm ${^texs:r}.aux

${texs:r} strips off the extension giving the Root name of each element in texs. The ${...}.aux causes the .aux to be appended, and the ${^...} causes the appending to happen element-wise.

-- 
Chris Johnson
johnch@uwec.edu


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

* Re: executing commands in directories containing specific files
  2014-02-12  1:17   ` Philip Dexter
@ 2014-02-12  2:17     ` Jan Larres
  0 siblings, 0 replies; 9+ messages in thread
From: Jan Larres @ 2014-02-12  2:17 UTC (permalink / raw)
  To: zsh-users

On 12/02/14 14:17, Philip Dexter wrote:
> On Tue, Feb 11, 2014 at 7:35 PM, Jan Larres <jan@majutsushi.net> wrote:
>> On 12/02/14 13:11, Leonardo Barbosa wrote:
>>> I'd like to find TeX files (find $HOME -type f -name '*.tex'). Let's say i
>>> have found files a.tex, b.tex, and c.tex. Now, i wanna remove a.aux, b.aux,
>>> c.aux. What's the best way of doing that?
>>
>> find $HOME -type f -name '*.tex' -exec rm {} \;
>>
> That won't get the aux files

Oh, whoops. I missed the differing extensions. In that case your
solution is probably best, except without removing the tex files
themselves:

  for f in $HOME/**/*.tex; do rm ${f:r}.aux; done

Jan


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

* Re: executing commands in directories containing specific files
  2014-02-12  0:11 executing commands in directories containing specific files Leonardo Barbosa
  2014-02-12  0:35 ` Jan Larres
  2014-02-12  1:53 ` Chris Johnson
@ 2014-02-12  5:13 ` Bart Schaefer
  2014-02-12  8:33   ` Michel
  2 siblings, 1 reply; 9+ messages in thread
From: Bart Schaefer @ 2014-02-12  5:13 UTC (permalink / raw)
  To: zsh-users

On Feb 11, 10:11pm, Leonardo Barbosa wrote:
}
} I'd like to find TeX files (find $HOME -type f -name '*.tex'). Let's say i
} have found files a.tex, b.tex, and c.tex. Now, i wanna remove a.aux, b.aux,
} c.aux. What's the best way of doing that?

I like using the (e) flag, but it's sometimes tricky to get right on the
first try because you have to be careful to match up the parens in the
reply=(...) assignment, the quotes around the expression, the outer set
of delimiters (I used [...] below) and the parens around the whole thing:

    rm **/*.tex(.e['reply=(${REPLY:r}.aux)'])

But you can also use colon-modifiers as glob qualifiers, so if the .tex
never appears anywhere but at the end:

    rm **/*.tex(.:s/.tex/.aux)

If you've already got the filenames, say, in an array:

    texi=( $(find $HOME -type f -name '*.tex') )

Colon-modifiers work on every word in an array, so you can use the "^"
flag (rcexpandparam) like so:

    rm ${^texi:r}.aux

Or you can just use one of the loops already suggested.


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

* Re: executing commands in directories containing specific files
  2014-02-12  5:13 ` Bart Schaefer
@ 2014-02-12  8:33   ` Michel
  2014-02-12  9:44     ` Leonardo Barbosa
  2014-02-12 18:33     ` Bart Schaefer
  0 siblings, 2 replies; 9+ messages in thread
From: Michel @ 2014-02-12  8:33 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

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

>
> I like using the (e) flag, but it's sometimes tricky to get right on the
> first try because you have to be careful to match up the parens in the
> reply=(...) assignment, the quotes around the expression, the outer set
> of delimiters (I used [...] below) and the parens around the whole thing:
>
>     rm **/*.tex(.e['reply=(${REPLY:r}.aux)'])
>
> But you can also use colon-modifiers as glob qualifiers, so if the .tex
> never appears anywhere but at the end:
>
>     rm **/*.tex(.:s/.tex/.aux)
>

thanks for this solutions interesting !


>
> If you've already got the filenames, say, in an array:
>
>     texi=( $(find $HOME -type f -name '*.tex') )
>

Why use find instead the glob way :
texi=( **/*.tex(.) )

When the result is use as a stream find is a beter way but to create an
array ?
_____________________
Michel BARRET

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

* Re: executing commands in directories containing specific files
  2014-02-12  8:33   ` Michel
@ 2014-02-12  9:44     ` Leonardo Barbosa
  2014-02-12 18:33     ` Bart Schaefer
  1 sibling, 0 replies; 9+ messages in thread
From: Leonardo Barbosa @ 2014-02-12  9:44 UTC (permalink / raw)
  To: Michel; +Cc: Bart Schaefer, zsh-users

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

All, thanks a lot. That worked!




On Wed, Feb 12, 2014 at 6:33 AM, Michel <michel.barret@gmail.com> wrote:

> >
> > I like using the (e) flag, but it's sometimes tricky to get right on the
> > first try because you have to be careful to match up the parens in the
> > reply=(...) assignment, the quotes around the expression, the outer set
> > of delimiters (I used [...] below) and the parens around the whole thing:
> >
> >     rm **/*.tex(.e['reply=(${REPLY:r}.aux)'])
> >
> > But you can also use colon-modifiers as glob qualifiers, so if the .tex
> > never appears anywhere but at the end:
> >
> >     rm **/*.tex(.:s/.tex/.aux)
> >
>
> thanks for this solutions interesting !
>
>
> >
> > If you've already got the filenames, say, in an array:
> >
> >     texi=( $(find $HOME -type f -name '*.tex') )
> >
>
> Why use find instead the glob way :
> texi=( **/*.tex(.) )
>
> When the result is use as a stream find is a beter way but to create an
> array ?
> _____________________
> Michel BARRET
>

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

* Re: executing commands in directories containing specific files
  2014-02-12  8:33   ` Michel
  2014-02-12  9:44     ` Leonardo Barbosa
@ 2014-02-12 18:33     ` Bart Schaefer
  1 sibling, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2014-02-12 18:33 UTC (permalink / raw)
  To: zsh-users

On Feb 12,  9:33am, Michel wrote:
} Subject: Re: executing commands in directories containing specific files
}
} > If you've already got the filenames, say, in an array:
} >
} >     texi=( $(find $HOME -type f -name '*.tex') )
} >
} 
} Why use find instead the glob way:
} texi=( **/*.tex(.) )

Leonardo had a "find" command in his original question, so I just copied
it, in case he already had a working script that was producing the list
of .tex files and he only needed a new part to change the suffix.


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

end of thread, other threads:[~2014-02-12 18:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-12  0:11 executing commands in directories containing specific files Leonardo Barbosa
2014-02-12  0:35 ` Jan Larres
2014-02-12  1:17   ` Philip Dexter
2014-02-12  2:17     ` Jan Larres
2014-02-12  1:53 ` Chris Johnson
2014-02-12  5:13 ` Bart Schaefer
2014-02-12  8:33   ` Michel
2014-02-12  9:44     ` Leonardo Barbosa
2014-02-12 18:33     ` Bart Schaefer

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).