Problem: suppose you have a bunch of jpeg files, with names such as
The command uses ImageMagick, it is for linux and it goes as
identify -format "%f %m\n" * | grep -v JPEG | awk '{ print $1 }' | xargs rmIdentify is an ImageMagick program that retrieves information about the image file, the -format option tells what to print (filename and format, as detected by the magic number).
The grep command takes all the lines that do *not* match "JPEG".
the awk takes the first word in the line (the filename).
The xargs concatenates the word to the command "rm" (REMOVE, again, pay attention!).
1 comment:
Hi,
You can do it with awk in a simpler way:
identify -format "%f %m\n" * | awk '$2 !~ /JPEG/ {system("rm " $1)}'
just change the format you don't want to delete
Post a Comment