BrilliantFocus
New Member
Hi guys,
Background: I have 5500 files that did not come with extensions (.jpg, pdf, docx, etc) and I would like to add extensions to the end of the base filenames for ease of use, if nothing else.
For my purposes, I used the file command in Bash in order to determine the output, parsed down the output after cutting and sorting came up with the following list of results.
ASCII text
Audio file with ID3 version 2.3.0, contains
Composite Document File V2 Document, corrupt
Composite Document File V2 Document, Little Endian, Os
Composite Document File V2 Document, Little Endian, Os
Composite Document File V2 Document, No summary info
data
GIF image data, version 89a, 2416 x 877
GIF image data, version 89a, 2416 x 908
GIF image data, version 89a, 2431 x 3168
GIF image data, version 89a, 2435 x 3168
HTML document, ISO-8859 text, with CRLF line terminators
HTML document, UTF-8 Unicode text, with very long lines
ISO Media, Apple QuickTime movie
ISO Media, MPEG v4 system, version 2
JPEG image data, EXIF standard
JPEG image data, EXIF standard 2.21
JPEG image data, EXIF standard, comment
JPEG image data, JFIF standard 1.00
JPEG image data, JFIF standard 1.00, comment
JPEG image data, JFIF standard 1.01
Macromedia Flash Video
Microsoft ASF
Microsoft Excel 2007+
Microsoft PowerPoint 2007+
Microsoft Word 2007+
OpenDocument Spreadsheet
OpenDocument Text
PDF document, version 1.0
PDF document, version 1.2
PDF document, version 1.3
PDF document, version 1.4
PDF document, version 1.5
PDF document, version 1.6
PDF document, version 1.7
PNG image data, 1186 x 383, 8-bit/color RGBA, non-interlaced
PNG image data, 1268 x 1649, 8-bit/color RGBA, non-interlaced
PNG image data, 1275 x 1750, 8-bit/color RGBA, non-interlaced
RAR archive data, v1d, os
Rich Text Format data, version 1, ANSI
Rich Text Format data, version 1, unknown character set
TIFF image data, little-endian
UTF-8 Unicode text
UTF-8 Unicode text, with very long lines
Zip archive data, at least v1.0 to extract
Zip archive data, at least v2.0 to extract
I pasted in the filename into the start of the line like so:
File1 File1: PDF document, version 1.0
And then I used a sed command to modify the documented comment from the file command like so:
sed 's|:||g;s|ASCII text|.txt|g;s|Audio file with ID3 version 2.3.0, contains|.mp3|g;s|Composite Document.*$|.docx|g;s|data||g;s|GIF.*$|.gif|g;s|HTML.*$|.html|g;s|ISO Media, Apple QuickTime movie|.mov|g;s|ISO Media, MPEG.*$|.mpeg|g;s|JPEG.*$|.jpg|g;s|Macromedia Flash Video|.flv|g;s|Microsoft ASF|.asf|g;s|Microsoft Excel 2007+|.xlsx|g;s|Microsoft PowerPoint 2007+|.pptx|g;s|Microsoft Word 2007+|.docx|g;s|OpenDocument Spreadsheet||g;s|OpenDocument Text|.odt|g;s|PDF.*$|.pdf|g;s|PNG.*$|.png|g;s|RAR archive data, v1d, os|.rar|g;s|Rich Text Format.*$|.rtf|g;s|TIFF image data, little-endian|.tiff|g;s|UTF-8 Unicode.*$|.txt|g;s|Zip.*$|.zip|g;s| .|.g' FILENAME
And then ran a while loop in order to change the file names like so:
while read file ; do mv $file ; done < FILENAME
-------------
I understand that I was able to accomplish what I wanted in the end, but there HAS to be a more elegant solution to this problem, right? I have spent hours googling and reading man pages for possible candidates, but have not discovered anything that works the way I would like it to automatically.
Am I missing something? Searching for the wrong keywords? Or does automatic extension addition not appear to be a tool that is commonly-enough needed to be present in common libraries?
Thanks!
Background: I have 5500 files that did not come with extensions (.jpg, pdf, docx, etc) and I would like to add extensions to the end of the base filenames for ease of use, if nothing else.
For my purposes, I used the file command in Bash in order to determine the output, parsed down the output after cutting and sorting came up with the following list of results.
ASCII text
Audio file with ID3 version 2.3.0, contains
Composite Document File V2 Document, corrupt
Composite Document File V2 Document, Little Endian, Os
Composite Document File V2 Document, Little Endian, Os
Composite Document File V2 Document, No summary info
data
GIF image data, version 89a, 2416 x 877
GIF image data, version 89a, 2416 x 908
GIF image data, version 89a, 2431 x 3168
GIF image data, version 89a, 2435 x 3168
HTML document, ISO-8859 text, with CRLF line terminators
HTML document, UTF-8 Unicode text, with very long lines
ISO Media, Apple QuickTime movie
ISO Media, MPEG v4 system, version 2
JPEG image data, EXIF standard
JPEG image data, EXIF standard 2.21
JPEG image data, EXIF standard, comment
JPEG image data, JFIF standard 1.00
JPEG image data, JFIF standard 1.00, comment
JPEG image data, JFIF standard 1.01
Macromedia Flash Video
Microsoft ASF
Microsoft Excel 2007+
Microsoft PowerPoint 2007+
Microsoft Word 2007+
OpenDocument Spreadsheet
OpenDocument Text
PDF document, version 1.0
PDF document, version 1.2
PDF document, version 1.3
PDF document, version 1.4
PDF document, version 1.5
PDF document, version 1.6
PDF document, version 1.7
PNG image data, 1186 x 383, 8-bit/color RGBA, non-interlaced
PNG image data, 1268 x 1649, 8-bit/color RGBA, non-interlaced
PNG image data, 1275 x 1750, 8-bit/color RGBA, non-interlaced
RAR archive data, v1d, os
Rich Text Format data, version 1, ANSI
Rich Text Format data, version 1, unknown character set
TIFF image data, little-endian
UTF-8 Unicode text
UTF-8 Unicode text, with very long lines
Zip archive data, at least v1.0 to extract
Zip archive data, at least v2.0 to extract
I pasted in the filename into the start of the line like so:
File1 File1: PDF document, version 1.0
And then I used a sed command to modify the documented comment from the file command like so:
sed 's|:||g;s|ASCII text|.txt|g;s|Audio file with ID3 version 2.3.0, contains|.mp3|g;s|Composite Document.*$|.docx|g;s|data||g;s|GIF.*$|.gif|g;s|HTML.*$|.html|g;s|ISO Media, Apple QuickTime movie|.mov|g;s|ISO Media, MPEG.*$|.mpeg|g;s|JPEG.*$|.jpg|g;s|Macromedia Flash Video|.flv|g;s|Microsoft ASF|.asf|g;s|Microsoft Excel 2007+|.xlsx|g;s|Microsoft PowerPoint 2007+|.pptx|g;s|Microsoft Word 2007+|.docx|g;s|OpenDocument Spreadsheet||g;s|OpenDocument Text|.odt|g;s|PDF.*$|.pdf|g;s|PNG.*$|.png|g;s|RAR archive data, v1d, os|.rar|g;s|Rich Text Format.*$|.rtf|g;s|TIFF image data, little-endian|.tiff|g;s|UTF-8 Unicode.*$|.txt|g;s|Zip.*$|.zip|g;s| .|.g' FILENAME
And then ran a while loop in order to change the file names like so:
while read file ; do mv $file ; done < FILENAME
-------------
I understand that I was able to accomplish what I wanted in the end, but there HAS to be a more elegant solution to this problem, right? I have spent hours googling and reading man pages for possible candidates, but have not discovered anything that works the way I would like it to automatically.
Am I missing something? Searching for the wrong keywords? Or does automatic extension addition not appear to be a tool that is commonly-enough needed to be present in common libraries?
Thanks!