Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing characters in text file 1

Status
Not open for further replies.

JtheRipper

IS-IT--Management
Oct 4, 2002
274
GB
Hi there,

I have a directory of files with all the same length and format i.e. 040601LV*, where * can be anything from A-Z, but single characters only, so no AA, AB, etc and the letter closest to A will show me the oldest file.

I want to compare the last character of each file, I can already loop through all files and read the last character in a variable with the help of the cut command. Now I want to compare the last letter of each file, start with the oldest file (letter A or closest to A is oldest), do something, go to next file and exit when done.

How do I compare the letters to one another and figure out which one is "older" than the other? I have thought of creating another text file with letters A-Z and giving them numerical values, but any other ideas will be appreciated!

Thanks,
J.
 
The following loop list the files, oldest first:
for file in 040601LV*
do
echo $file
done


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Great! Thanks a lot, exactly what I wanted.

Now, can you pls explain WHY it works? Will the loop automatically list the files alphabetically?

Thanks again,
J.
 
This is how the shell globbing works.
When in the relevant directory, simply execute this command:
echo 040601LV*


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top