shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Dica do Ivan (renomear arquivos)


From: jimmy
Subject: Re: [shell-script] Dica do Ivan (renomear arquivos)
Date: Fri, 13 Feb 2009 09:06:50 -0200
User-agent: Mutt/1.4.2.3i

On Fri, Feb 13, 2009 at 12:41:50AM -0200, Fabiano Caixeta Duarte wrote:
> 2009/2/12 Julio C. Neves <address@hidden>
> 
> > Já que a brincadeira é fazer one liners, veja se esse funciona:
> >
> >  paste <(ls *02*) <(ls *02* | sed 's/02/03/') | xargs -tL1 mv
> >
> > o -t em -tL1 é só para mostrar o que ele está fazendo. Se for trocado
> > por-p, ficará
> > interativo e pedirá confirmação antes de mover. Quem não entendeu,
> > leia aqui<
> > https://wiki.softwarelivre.org/TWikiBar/TWikiBarPapo011#Substitui_o_de_processo
> > >ou
> > aqui<
> > https://twiki.softwarelivre.org/TWikiBar/TWikiBarBirinaite#Passando_par_metros_com_xargs
> > >.
> > Está em português e a leitura é fácil.
> > --
> > Abração,
> > Julio
> > *Cursos de Shell e Zenity nos finais de semana:
> > - Em SP ligue (11) 2125-4747;
> > - Em DF ligue (61) 3223-3000;
> > - No RJ brevemente;
> > - Turmas fechadas em outras cidades ligue (21) 8112-9988
> > *
> > 2009/2/11 Ivan lopes <address@hidden>
> >
> > >   * problema:
> > > dado os arquivos, substituir o valor 02 por 03.
> > >
> > > $ ls *.txt
> > > xml-xmllint-sample-validate-02-00.txt
> > > xml-xmllint-sample-validate-02-note.xml.txt
> > > xml-xmllint-sample-validate-02-note.dtd.txt
> > > xml-xmllint-sample-validate-02-note.xsd.txt
> > >
> > > * forma normal de resolver o problema:
> > > $ mv xml-xmllint-sample-validate-02-00.txt
> > > xml-xmllint-sample-validate-03-00.txt
> > > $ mv xml-xmllint-sample-validate-02-note.xml.txt
> > > xml-xmllint-sample-validate-03-note.xml.txt
> > > $ mv xml-xmllint-sample-validate-02-note.dtd.txt
> > > xml-xmllint-sample-validate-03-note.dtd.txt
> > > $ mv xml-xmllint-sample-validate-02-note.xsd.txt
> > > xml-xmllint-sample-validate-03-note.xsd.txt
> > >
> > > * forma ninja! ou Julhesca! ==> ( adjetivo relativo ao cara muito bom em
> > > Shell )
> > >
> > > hum! vejamos,
> > > - dupliquei a entrada : 'p'
> > > - substitui `02' por `03' : 's/02/03/'
> > > - adicionei mv na frente da linha :'s/^/mv /'
> > > - removi os fins de linha :'N;s/\n/ /'
> > >
> > > moleza! sed nele!
> > > $ ls *.txt| sed 'p; s/02/03/' | sed 'N;s/\n/ /; s/^/mv /'
> > > mv xml-xmllint-sample-validate-02-00.txt
> > > xml-xmllint-sample-validate-03-00.txt
> > > mv xml-xmllint-sample-validate-02-note.dtd.txt
> > > xml-xmllint-sample-validate-03-note.dtd.txt
> > > mv xml-xmllint-sample-validate-02-note.xml.txt
> > > xml-xmllint-sample-validate-03-note.xml.txt
> > > mv xml-xmllint-sample-validate-02-note.xsd.txt
> > > xml-xmllint-sample-validate-03-note.xsd.txt
> > >
> > > para que um texto vire uma acao! `sh' nele!
> > >
> > > $ ls *.txt| sed 'p; s/02/03/' | sed 'N;s/\n/ /; s/^/mv /'| sh
> > >
> > > !!-Atencao-!!
> > > o bacana desse exemplo, eh que vc pode colocar uma regex no lugar do
> > > `02' ... entao qualquer tipo de substituicao pode acontecer.
> > >
> > > ***transformando essa dica em algo util! <<--- achou que eu tinha
> > > esquecido!
> > > $ cat rename.sh
> > > #!/bin/bash
> > >
> > > REGEX=$1
> > > _STR_=$2
> > > # ----------------------------------------------------------
> > > cat -|
> > > sed "p; s/$REGEX/$_STR_/" | sed 'N;s/\n/ /; s/^/mv /'
> > >
> > > # ----------------------------------------------------------
> > > exit 0
> > >
> > > Uso:
> > > $ ls *.txt| ./rename.sh java c++
> > > mv xml-xmllint-sample-java-03-00.txt xml-xmllint-sample-c++-03-00.txt
> > > mv xml-xmllint-sample-java-03-note.dtd.txt
> > > xml-xmllint-sample-c++-03-note.dtd.txt
> > > mv xml-xmllint-sample-java-03-note.xml.txt
> > > xml-xmllint-sample-c++-03-note.xml.txt
> > > mv xml-xmllint-sample-java-03-note.xsd.txt
> > > xml-xmllint-sample-c++-03-note.xsd.txt
> > >
> > > []'s
> > > Ivan! :)
> >
> 
> Mais uma forma. Esta é bash puro!
> 
> for i in *02*; do echo mv ${i} ${i/02/03}; done
> 
> -- 
> Fabiano Caixeta Duarte
> Especialista em Redes de Computadores
> Linux User #195299
> Ribeirão Preto - SP
> 
> 
> ------------------------------------

apenas para constar,

 $ rename 02 03 *



-- 
" Não manejo bem as palavras
Mas manipulo bem as strings."
------------------------------


reply via email to

[Prev in Thread] Current Thread [Next in Thread]