innova
11-01-2004, 05:09 PM
Hi,
I have a problem I am trying to solve in the most effective manner possible - at least the most effective in a bash script. I realize that perl / etc would be better for this, but I wish to stay in shell for the time being.
The problem:
I have 3 files that I am working with, a "Translation" file (somewhat akin to how locale works), a "Settings" file, and various other files that I need to check against.
Sample "Translation" File:
alias1=realname1
alias2=realname2
alias3=realname3
Sample "Settings" File:
alias1=value1
alias2=value2
alias3=value3
Sample "file to check against"
realname1=value1
realname2=value2
realname3=value3
I think you can deduce what I am doing here. I am using the "Translation" file as an abstraction layer for my settings file and the files I want to check the values against.
Now the problem is...
The Settings file may have fewer elements than the Translation file. Therefore, I need to match the elements in field 1 of the settings to field 1 of the translation entries.
I am currently using arrays to do this. As you know, bash doesnt have associative arrays, just zero-indexed arrays. Thus, I need to create 2 arrays for each file, one containing field 1 and the other field 2. Works fine, but the problem is.. ITS SLOW AS HELL.
I am looking for ideas how to do this not using arrays. In summary: I need to match entries in settings and translation. Using those entries, I need to construct a list of realnames and their associated values. I then will use sed to parse files and overwrite the settings that do not match the ones in the list.
I hope this makes sense :)
I have a problem I am trying to solve in the most effective manner possible - at least the most effective in a bash script. I realize that perl / etc would be better for this, but I wish to stay in shell for the time being.
The problem:
I have 3 files that I am working with, a "Translation" file (somewhat akin to how locale works), a "Settings" file, and various other files that I need to check against.
Sample "Translation" File:
alias1=realname1
alias2=realname2
alias3=realname3
Sample "Settings" File:
alias1=value1
alias2=value2
alias3=value3
Sample "file to check against"
realname1=value1
realname2=value2
realname3=value3
I think you can deduce what I am doing here. I am using the "Translation" file as an abstraction layer for my settings file and the files I want to check the values against.
Now the problem is...
The Settings file may have fewer elements than the Translation file. Therefore, I need to match the elements in field 1 of the settings to field 1 of the translation entries.
I am currently using arrays to do this. As you know, bash doesnt have associative arrays, just zero-indexed arrays. Thus, I need to create 2 arrays for each file, one containing field 1 and the other field 2. Works fine, but the problem is.. ITS SLOW AS HELL.
I am looking for ideas how to do this not using arrays. In summary: I need to match entries in settings and translation. Using those entries, I need to construct a list of realnames and their associated values. I then will use sed to parse files and overwrite the settings that do not match the ones in the list.
I hope this makes sense :)
