[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

RE: [TEKNIK] Omdøbning af mange filer



> 2012/6/28 Jens Bang <sslug@sslug>:
> > Jeg forstår ikek hvad du mener...
> >
> > Jeg skal bruge find i stedet for *?
> >
> 
> ja command substitue find, hvis du bruger mellemrum i dine fil navne
> tror for det er et nyt argument. så pipe til tr fx
> for file in `find . | tr ' ' '_'`
> 
> > Mht sed scriptet: Vil du rette direkte i filnavnet?
> 
>   Man kan ikke rename i unix kun move.
> 
> > Eller lade sed scriptet generere en streng der indeholder det filnavn
> der skal renames
> > til og så bruge mv?
> >
> > -- Jens
> 
>   Hmm jeg vil arbejde med min for variable file fx
> 
> mv $file `echo $file | sed 's/badchars/goodchars/g' | tr '_' ' '`
> 
>   Du kan samle flere sed kommandoer i en fil og køre dem samlet i
> stedet for at blive ved med at pipe til sed eller bruge noget regex
> hvis du har et logisk mønster.
> 
>   man lidt de forskellige kommandoer og din shell.
> 
>   -- Hilsen Andreas
> 

Et lille script der håndterer det meste af det.


#!/bin/bash
#Start
convertillegalchar () {
tmpvar="${1//</_}"
tmpvar="${tmpvar//>/_}"
tmpvar="${tmpvar//\?/_}"
tmpvar="${tmpvar//\*/_}"
tmpvar="${tmpvar//:/_}"
echo "$tmpvar"
}


for file in $(find . -type f); do
  newfilename="$(convertillegalchar "$file")"
  if test "$file" != "$newfilename"; then
    echo "$newfilename"
  fi
done
#End

Her håndterer man flytning af fil incl. fejlkoder osv. inde i if-konstruktion.


Filer i mappe TEST:

ls -x TEST
a<b>c?d*e:  abc>.txt

Kørselsresultat:

./TEST/abc_.txt
./TEST/a_b_c_d_e_



Med venlig hilsen / Regards

Frank Larsen
Kimik IT A/S
PO Box 740
3900 Nuuk
Greenland
Mail : sslug@sslug
Phone: +299 34 20 00






 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2012-07-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *