12-26-2008
2,
0
Join Date: Dec 2008
Last Activity: 26 December 2008, 2:40 PM EST
Posts: 2
Thanks Given: 0
Thanked 0 Times in 0 Posts
Help with how to account for changing filenames
The files below are essentially “lookup files” used in a series of scripts that run through the look up files and grab the correct Group Name and File Type and then unless I have the file name specified will replace the variable with the corresponding group name when processing the files before FTPing them to remote servers.
I have a replace string that will replace ZZZZ with the Group Name. Up to this point I have always known what my input will be so that I can specify my output.
File_1 GROUP NAME:
JUNK
BUNK
GTO1
...
File_2 FILE TYPE:
JUNK TEST
JUNK EMAIL
BUNK TEST
BUNK PART
GTO1 PART
GTO1 EMAIL
...
File_3 Destination File NAME: (ZZZZ is a place holder and will be replaced in the actual file name with Group name after processing.)
JUNK EMAIL EMAIL.ZZZZ.date.txt
JUNK TEST JUNK_TEST.date.txt
BUNK TEST TEST.ZZZZ.date.txt
GTO1 PART GTO1.ZZZZ.date.txt
GTO1 TEST GTO1TEST1.date.txt
...
Here is my replace funtion which works just fine for ZZZZ
sub_qs()
{
typeset string=$1;
typeset replace_string=$2;
string=`echo $string|awk -v replace_string=$replace_string '{gsub(/\Z\Z\Z\Z/,replace_string); print $0;}'`
echo $string
}
So now that the background is over, I now have an issue that I am not sure how to handle.
I need to add new file type for certain group names for which I cannot account for the complete filename because it will different every time it is sent to me.
I was thinking that my lookup files should have entries below added to them to account for it, What I do not know how to do is to bring the YYY stright from the file name but I do know that I will only have to account for 3 characters.
File_2 FILE TYPE:
GTO1 EMAIL_2
File_3 FILE NAME:
GTO1 EMAIL_2 GTO1.ZZZZYYY.date.txt
or I would be fine with
GTO1 EMAIL_2 GTO1.GTO1YYY.date.txt (and not using my current replace string)
Thanks for any and all assistance.