Re: Removing non matching files




"sil" <dsphunxion@xxxxxxxxx> wrote in message news:1190031705.593445.167780@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I've got an issue hoping someone could provide a better fix for
(current method works but is sloppy). I've
20,000+ directories with the following in them:

-rwx------ 1 root root 5.9K Sep 13 00:37 msg0010.gsm
-rw------- 1 root root 232 Sep 13 00:37 msg0010.txt

However at times I get this:

-rw------- 1 root root 232 Sep 13 00:37 msg0010.txt

Which is giving me issues (when there is a txt file and no gsm or wav
to match), I need to be able to look from the top directory, go into
every single directory and remove the *.txt file if there is no
matching *.gsm or wav file.


-rwx------ 1 root root 5.9K Sep 13 00:37 msg0010.gsm
-rw------- 1 root root 232 Sep 13 00:37 msg0010.txt
-rw------- 1 root root 232 Sep 13 00:47 msg0011.txt

*11.txt would have to go and so on.


The approach I would take is this: use find to list the files
with -printf to pad each name to the same length, and
then pipe to uniq which should compare the names
only up to but not including their .txt/.wav suffixes.

Note that I am assuming Gnu utilities: your system's native
find and uniq (and xargs) commands may differ.

find topdir -type f -printf "%10h:%f\n" |uniq --check-chars=17

You might need to change the details (especially the 10 and
17 depending on how long the name of topdir is) depending on
your actual needs (and remember the \n). When you are happy,
you can pipe the output to xargs --no-run-if-empty rm

--
John.


.



Relevant Pages

  • Re: Removing non matching files
    ... matching *.gsm or wav file. ... find and uniq commands may differ. ... 17 depending on how long the name of topdir is) depending on ... uniq needs -u as well! ...
    (comp.unix.shell)
  • Re: Removing non matching files
    ... On 2007-09-17, Janis wrote: ... (current method works but is sloppy). ... Which is giving me issues (when there is a txt file and no gsm or wav ... matching *.gsm or wav file. ...
    (comp.unix.shell)
  • Re: Any idea when the Pre will be unlocked?
    ... anywhere from three to six months depending on who you ask. ... The GSM model has been making the rounds of the gadget blogosphere. ... The wildcard in this game is probably the Eos which will Palm's next ... Assuming the Pre is selling as well as Palm claims it ...
    (comp.sys.palmtops.pilot)
  • Re: Next Big CDMA release?
    ... GSM max at 9.6kbps, 14.4kbps depending on network. ... AFAIK Verizon is CDMA, and will deploy EV-DO in some places to start with. ...
    (microsoft.public.pocketpc.phone_edition)
  • Re: Quesiton for change sample rate of WAV?
    ... > resample it. ... I dont wanna let my sounds sound so different from before. ... u-law will reduce the .wav file in half, and ADPCM will reduce it to one forth ... If your .wav file is just voice and not music then GSM will ...
    (microsoft.public.win32.programmer.directx.audio)