Sponsored Content
Top Forums Shell Programming and Scripting Recursive File Renaming & Natural Sorting (Bash) Post 302749637 by Corona688 on Friday 28th of December 2012 06:31:39 PM
Old 12-28-2012
This kind of problem always seems so easy until you try. I've made many attempts, but they're never quite satisfactory. I haven't found any kind of general solutions that humans can't break, and trying to fix up the corners just makes it easier to confuse.

Imagine this sequence of files for instance.

Code:
file1.jpg
file2.jpg
...
file8.jpg
file9.bmp
file10.jpg

Is it part of the sequence, or is it not? It's ambiguous.

Or how about this one:

Code:
cover.jpg
asd1.jpg
asd2.jpg
asd3.jpeg

Does cover belong at the beginning or the end, and how would you tell a program to know this? Are you sure the cover will always belong at the beginning?

Should we assume the jpeg is a typo because they have the same prefix of asd? Where does the prefix start, where does it end, and how is it deliniated from the rest?

Or this sequence:

Code:
cover for some file name containing 1234.jpg
some file name containing 1234 #1.jpg
some file name containing 1234 #1.jpg
some file name containing 1234 #1.jpg
...
some file name containing 1234 #365.jpg

Do 'cover for some file name containing 1234' and 'some file name containing 1234 #' belong to the same sequence or not? Should # be considered part of the name?

And what happens when you get a sequence like this?

Code:
1a.jpg
1b.jpg
1c.jpg
1.jpg
2.jpg
3.jpg
4.jpg

You end up tacking on special case after special case after special case onto your program to handle all these special things -- and then you get something like this thrown at you:

Code:
file1a.jpg
file2a.jpg
file3a.jpg
file4a.jpg

Or maybe the files all have 'cover' in their name so they all end up being 'special' and jammed in first in no particular order, or even skipped. Or this, or that, or a million other things.

If humans would just name their files in rational, consistent, predictable ways, they wouldn't need reordering. But all too often human context is needed to explain where things belong.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

recursive sorting

In the ls command, -t option and -R option dont work simultaneously. ls -t ---> lists the files with sorting based on file date ls -R ---> lists the files recursively. How to make utilize both in the same command.? I want to sort the recursive files listing.. (1 Reply)
Discussion started by: fermisoft
1 Replies

2. Shell Programming and Scripting

successive file renaming & overwriting

Hi all, In our webserver customer wants to see the latest 10 files arrived. So the names are hardcoded in webpage like : filename_01.txt filename_02.txt .... .... filename_10.txt where the filename_01.txt is the latest one (typically the output of ls -1t) in the /../webpage directory.... (2 Replies)
Discussion started by: sabyasm
2 Replies

3. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies

4. UNIX for Dummies Questions & Answers

Renaming file in Recursive folders

I have UWin version of Unix for Destop I have files with extension *.abc. I want to rename it to *.csv. Some of the filenames have spaces. I also to rename the files with extension *.abc in the corresponding subfolders ex == abc def.abc ghi jkl.abc mnopqr.abc uvwxyz.abc rename as... (4 Replies)
Discussion started by: bobbygsk
4 Replies

5. Shell Programming and Scripting

Bash recursive scripting

How does one make a recursive script in the bash shell? For instance, if I wanted a script that stepped through the directory structure starting with . and going to the deepest level, and ran make in each folder in the tree. Yeah, I know a makefile could be setup to do this, but it's not... (11 Replies)
Discussion started by: James McMurray
11 Replies

6. Shell Programming and Scripting

Bash: renaming file issues.

Hi, i want to rename a group of directories and files of my music, some items are like this: - , for directories. - , for files. I want to do something like this: , for directories. , for files. This is my code: #!/bin/bash for fname in *.mp3; do echo item: $fname mv... (2 Replies)
Discussion started by: josco1982
2 Replies

7. Solaris

Monitoring log file for entries - Find command & sorting

hi, I would like to monitor a log file, which rolls over, everytime a server is restarted. I would like to grep for a string, and to be more efficient i'd like to grep only newly appended data. so something like a 'tail -f' would do, however, as the log rolls over i think a 'tail -F' is... (2 Replies)
Discussion started by: horhif
2 Replies

8. Shell Programming and Scripting

Renaming files & folder according to the similarities in filenames

hello does someone want to help me for this one ? i want to rename files & a folder according to the similarities in filenames for example : the file with the good name cglogo tougl1953 dgmel bogd 01 -- ttgductoog ggdté gollogtd.ext1the others files needed to be renamed cglogo... (5 Replies)
Discussion started by: mc2z674gj
5 Replies

9. UNIX for Dummies Questions & Answers

[solved] Where & what bash env file, Mac OS?

Hi! I wanted to simplify my bash prompt, so I edited my etc/bashrc file. I thought this was the file that would override any other env files. When I opened it, I saw that the way it was setup was not what my prompt looked like, although I forget exactly what was there. But i edited it the way I... (1 Reply)
Discussion started by: sudon't
1 Replies

10. Shell Programming and Scripting

[Solved] BASH - chaining TEST and COMMAND with && and II

Can you explain what this line of script is doing. What I have understood is : -- variable C is the name of a software which is either not installed, so it must be installed or allready installed and then should be update if newer version found -- branch B="$B $C" is to install the software --... (4 Replies)
Discussion started by: jcdole
4 Replies
JPEGICC(1)						      General Commands Manual							JPEGICC(1)

NAME
jpegicc - little cms ICC profile applier for JPEG. SYNOPSIS
jpegicc [options] input.jpg output.jpg DESCRIPTION
lcms is a standalone CMM engine, which deals with the color management. It implements a fast transformation between ICC profiles. jpegicc is little cms ICC profile applier for JPEG. OPTIONS
-b Black point compensation. -c <0,1,2,3> Precalculates transform. (0=Off, 1=Normal, 2=Hi-res, 3=LoRes) [defaults to 1] -g Marks out-of-gamut colors on softproof. -h <0,1,2> Show summary of options and examples. -i profile Input profile (defaults to sRGB). -m <0,1,2,3> SoftProof intent. -n Ignore embedded profile. -p profile Soft proof profile -o profile Output profile (defaults to sRGB). -q <0..100> Output JPEG quality. -t <0,1,2,3> Intent (0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute). -v Verbose. EXAMPLES
To color correct from scanner to sRGB: jpegicc -iscanner.icm in.jpg out.jpg To convert from monitor1 to monitor2: jpegicc -imon1.icm -omon2.icm in.jpg out.jpg To make a CMYK separation: jpegicc -oprinter.icm inrgb.jpg outcmyk.jpg To recover sRGB from a CMYK separation: jpegicc -iprinter.icm incmyk.jpg outrgb.jpg To convert from CIELab ITU/Fax JPEG to sRGB jpegicc -iitufax.icm in.jpg out.jpg NOTES
For suggestions, comments, bug reports etc. send mail to info@littlecms.com. SEE ALSO
tifficc(1), icc2ps(1), icclink(1), icctrans(1), wtpt(1) AUTHOR
This manual page was written by Shiju p. Nair <shiju.p@gmail.com>, for the Debian project. September 30, 2004 JPEGICC(1)
All times are GMT -4. The time now is 08:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy