I have a script file that uses import and load commands to bring in scripts from other files. I am trying to convert these scripts to a new language but it is hard to follow the variables through all of the different imports/loads. I am trying to write a BASH script to go through a file and import all the text from the included/imported files inline where it was called.
Final Solution Used!
sed -e 's/\\/\//g' test.restomatic | awk '{if ($1 ~ /^(LOAD|IMPORT)/) system("cat " $2); else print;}' > /cygdrive/c/bashScripts/testing.txt
Sample of Original File:
LOAD ..\..\..\..\GlobalSuccess\IdentityShardCreate_Success.rcq
REPLACE /rest-client/request/url/*shard* "//{$OKEnv}"
EXPECT HEADER SERVER
EXPECT HEADER DATE
EXPECT RETURN-CODE 201
RUN
IMPORT ..\..\..\..\GlobalSuccess\IdentityEnvironmentCreateNewEnvironmentFromShard_Success.rcq
REPLACE /rest-client/request/url/*shard* "//{$OKEnv}/environment"
EXPECT HEADER Server
EXPECT HEADER Date
EXPECT RETURN-CODE 204
RUN
ASSIGN ShardTypeControl 1
LOOP ShardTypeControl
ASSIGN OKShard2 {$ShardNames[{$ShardTypeControl}]}
LOAD ..\..\..\..\GlobalSuccess\IdentityEnvironmentAddShardToEnvironment_Success.rcq
REPLACE /rest-client/request/url/*shard* "//{$OKShard2}/environment/{$OKEnv}"
Example of desired results of output file:
Original File (OF) Start
(OF) Line 1
(OF) Line 2
(OF) Line 3
Line 1 of Imported File - would have been (OF) line 4
Line 2 of Imported File
(OF) Line 5
(OF) Line 6
Line 1 of Loaded File - would have been (OF) line 7
Line 2 of Loaded File
Line 3 of Loaded File
(OF) Line 8
Line 1 of Second Imported File - would have been (OF) line 9
Line 2 of Second Imported File
All this can be combined in single awk command like this: