Converting Data - Integer to string variable
Hi Forum,
I need to write a script that will look at a file name with a 13 digit number and convert it to a human friendly name. The numbers need to be broken down in stages (is this called parsing?). For example 1004030091401 is broken down to 1 means retail then then next three digits 044 refer to the brand, the next two digits 03 refer to the product class, the next three digits 009 is the style the next two digits is the colour 14 and lastly the two remaining digits are which version it is, in this instance version 1 (for multiple photos of products etc). The desirable outcome of all of this particular example wouldbe a text file with 7 columns 1004030091401|Retail|Alpine_Stars|Textile_Jacket|AST-1 WP|01 I think I need to write an array to store all the variables I'll need. Then parse each file in turn and lastly output to a text file or similar? Any help would be greatly appreciated as I don't know where to start with this one. Thanks in anticipation. |
So you have told us how to break the number down, which is fairly easy in a multitude of languages (which you haven't said which one you want to use / try), but you have not explained
how the conversion of the numbers will be worked out, ie. how do we convert 1 into Retail?? Is this data stored elsewhere? |
Have a look at this:
Code:
#!/bin/bash Code:
$ ls -l Code:
shopt -s extglob Code:
retail=( dummy retail foo bar ) Code:
for THISFILE in [0-9]* Code:
RET=${THISFILE:0:1} Code:
echo "$THISFILE|${retail[RET]}|${brand[BRA]}|${class[CLA]}|${style[STY]}|${colour[COL]}|$VER" >> outfile |
Thanks very much Druuna, I'll try this later on and let you now how I got on.
|
All times are GMT -5. The time now is 12:50 AM. |