Re: Scripting names from a file

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

 



On Wednesday 29 September 2004 06:32, Nifty Hat Mitch wrote:
> On Tue, Sep 28, 2004 at 04:53:54PM +0200, Chadley Wilson wrote:
> > > You don't need a script for that. Something simple as:
> >
> > OK Maybe I am trying to be too clever in my simplification of the
> > senario, so maybe this helps: I have a directory with files in it, I
> > also have a text file with a list of certian files, I need to mv the
> > files listed in the text files out of the dir into a new dir which I
> > have created.  Does that make more sense?
>
> I am lazy and feel handy with in vi.
>
> Since you have a file full of file names
> And since I have no clue how the file was generated
> and validated.... I want to inspect the file first.
>
> And, if this is a one time action....
>
> I tend to just make a copy of the file
> and edit it to be a script.  Working in the
> editor can permit me to see problems.
>
>     cp ./listOfiles listOfiles.sh
>
>     vi ./listOfiles.sh
>  Check the first and last lines,
>  these not smiley faces but checking will make ya happy.
>
>     :{
>     :0
>     :}
>     :$
>
>  search for white space and meta characters ... 6 ways to sunday...
>  a meta char discovery script line would be handy I can never
>  recall them all.  Mostly I just read the file... I do search for the
>  obvious.
>
>     /
>     /\t
>     /'
>     /"
>     /\$
>     /&
>     /@
>     /#
>     /?
>     />
>     /<
>     /-
>     /(
>     /)
>     /{
>     /}
>     /[
>     /]
>     /+
>     /\*
>     /\.
>     /:
>     /;
>     /|
>     /!
>
>  turn it into a scrip.
>
>     :1,$s/^/mv -i /
>     :1,$s/$/ new-dir/
>
>  If ok...
>
>     :wq
>
>     bash -n < ./listOfiles.sh | less
>     bash < ./listOfiles.sh
>
>
> The advantage is that looking at the listOfiles
> is part of the process.   My partial list of meta
> char searches might indicate the scope of potential
> pitfalls.
>
> I can search for spaces and meta characters with vim I can also build it in
> safe steps to validate the lines...  i.e. replace "mv " with "echo" or
> "stat"....
>
> I can insert "set -x" to make it noisy/verbose.
>
> If I am going to do this again and again then
> I would do some more interesting looping and scripting.
> Clearly some safety testing of the input should be
> added.
>
>  cat listOfiles | while read i
>  do
> 	echo ===========================
>  	echo $i
> 	mv -i $i newdir
>  done | less
>
> or...
>
>  while read i < listOfiles
>  do
> 	echo ===========================
>  	echo $i
> 	mv -i $i newdir
>  done | less
>
>
> YMMV.
>
>
> --

WOW! 
Tom                      Are you trying to frighten me?
Your doing a good job, ;->
Listen buddy thanks a million, I do appreciate the input the file in question 
had a list of mp3's which had been renamed removing the funny characters from 
the names and we eneded up with several text files containing lists of mp3 
sorted into various categories, the problem was we could tell if we missed 
any. So I created a directory for each text files content eg rave, rock, 
solo, alternative etc.... 
Then I ran this.
for i in `cat text_text_file`; do 
mv $1.mp3 /dest/dir
done
 however it failed as I had gotten confused and was in the wrong dir. This 
hapens when you constantly switch terminals ;->
anyway we are all done now and have discovered that there are very few left to 
sort.
Thanks again friend,
I would like to learn how to script like you though. ;-)
 

> 	T o m  M i t c h e l l
> 	Me, I would "Rather" Not.

-- 
Chadley Wilson
Redhat Certified Technician 
Cert Number: 603004708291270
Pinnacle Micro
Manufacturers of Proline Computers
====================================
Exercise freedom, Use LINUX
=====================================


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux