Hello again, straight dope. You may remember me from last time, asking for help on writing a linux script, and now I humbly come to you for help once again. First let me describe what my task is, and then I’ll put up my ideas in pseudo-code for how I think it could be done.
So we have these things called disklists, and there are a lot of them, they are just simple text files. An example disklist would be “disklist215001702” where the 21500 is a variable called r_line, and the 1702 is a variable called r_stat. These disk lists advance by twos (they are all even). So the previous file would be disklist215001700, disklist215001698, etc.
Now, what we end up having to do with these disklists is to cat ranges of them into a single file. Example: All the disklists between & including 215001224 and 215001262 get cat’d together into a single file called disklist215001224-215001262. There is similarly a disklist215001264-215001302. So on and so on until the last file, disklist215001664-disklist215001702 (12 total disklist-range files for every r_line).
The r_stat ranges/values are the same for every r_line, so here’s what I need the script to do. I need the user to be able to pass the parameter r_line to the script, and then the script goes through and cats together all the disklists in the current directory of that given r_line and creates the given ranged-disklist files.
I’m pretty sure I know the theory behind how to code this, but I’m not so great with the linux script syntax and the cat command and was hoping you could provide me with some pointers. Here is my idea.
r_line = user input
r_stat = 1224 [this is always the first r_stat value and will increase by 2 until reaching a maximum value of 1702]
r_stat_first = 1224 [this variable will be used as the first r_stat value in the output file name, starting at 1224 and advancing by 40 each time until 1664]
r_stat_last = 1262 [this variable will be used as the last r_stat value in the output file name, starting at 1262 and advancing by 40 each time until 1702]
r_count = 1 [This variable will count the number of r_stats added to a given disklist-range file, so that after 20 have been added, it will quit and start a new file]
t_count = 1 [This variable will count the total number of disklist files output, so when it gets to 12 total it will quit the loop. There are always 12 disklist-range files created]
for(t_count <= 12, t_count = t_count + 1)
for(r_count <=20, r_count = r_count + 1)
[INDENT]cat {“disklist”+string(r_line)+string(r_stat)} > {“disklist”+ string(r_line) + string(r_stat_first) + “-” + string(r_line) + string(r_stat_last)}[/INDENT]
[INDENT]r_stat = r_stat + 2[/INDENT]
r_stat_first = r_stat_first + 40
r_stat_last = r_stat_last + 40
I’m worried that the cat stuff I have up there is going to be overwriting the same output file everytime, and I’m not sure how to get around it. So if you could analyze that above piece of pseudo-code and let me know if you think it would work for what I need, that’d be great. And then if you could help me translate it into linux scripting language, it’d be doubly great! I’ve done my best to be explicit as possible but let me just re-iterate in a simplified what I need done, using 21500 as an example r_line:
cat disklist215001224 disklist215001226 … disklist215001262 > disklist215001224-215001262
cat disklist215001264 disklist215001266 … disklist215001302 > disklist215001264-215001302
cat disklist215001304 … disklist215001342> disklist215001304-215001342
cat disklist215001344 … disklist215001382> disklist215001344-215001382
cat … > disklist215001384-215001422
cat … > disklist215001424-215001462
cat … > disklist215001464-215001502
cat … > disklist215001504-215001542
cat … > disklist215001544-215001582
cat … > disklist215001584-215001622
cat … > disklist215001624-215001662
cat … > disklist215001664-215001702