[plug] Shell Tips

Leon Brooks leon at brooks.smileys.net
Wed Mar 10 10:32:30 WST 1999


HILL Walter wrote:
> I have approximately 7000 word-processing files in a propriety format
> (Enable if you  must know). The files have been created using a template
> (one of half a dozen different types). I've got the job of converting
> the files into a format suitable for importing into a database Probably
> <TAB> delimited). I intend on writing the conversion programme(s) in C
> (unless some one has a better idea).

> I firstly want to separate the files of similar type into different
> directories.

> I'd like to do this by examining the internal structure of
> the file, if it corresponds to a known layout write the filename to a
> text file. Then I'd like to use ???? to read the text file line by line,
> and move all the corresponding files elsewhere. By doing this I can (i)
> group 'like' files and (ii) see what is left over in case there are some
> other files.

Simplest way:

mkdir type1 type2 type3
mv `grep -l first-magic-string *` type1
mv `grep -l second-magic-string *` type2
mv `grep -l third-magic-string *` type3

... substituting appropriate values for the nth-magic-string words.
Leftovers are now in ./ and all else is categorised by dir. Later, you
can do:

cd type1
type1processor *

...or, for the fainthearted...

cd type1
for x in *; do type1processor $x; done

...or, if the processing program is really thick...

cd type1
for x in *.filetype; do type1processor $x `basename $x
.filetype`.newfiletype; done

> The files represent ten years worth of accumulated data and originally
> existed on our first 386 which cost $9000 and had a MB of RAM.

Remember the first three laws of computing: (1) make reliable backups
first (2) make more backups (3) make even more backups

-- 
We are sorry, but the number you have dialed is imaginary. 
Please rotate your phone 90 degrees and try again. -- David Grabiner


More information about the plug mailing list