Thanks FRANS! This looks a lot simpler than I thought it would be. I'll try it out as soon as i get on my linux box.
I for the most part understand whats happening here. Could you explain the purpose of the ":0:5" in this line? I found what the curly brackets do, but as of yet, not the colons.
if [ "${LINE:0:5}" = "data7" ]
Thanks for all the help!
---------- Post updated at 12:05 PM ---------- Previous update was at 10:43 AM ----------
As far as samples go, i have a file (format unknown). There are about 15000 lines or so that contain the word "prisoner". Each prisoner will be assigned a number that will be pulled from a .csv file. The input file looks like this (only right around 44000 lines long):
Type: SystemDeclarationData;7
1BN22IN prisoner
U0010000003
prisoner VIII SP
1
1
25
-1
0
0
0
0
0
Type: SupplyLoad;4
0
0
end;
end;
Type: SystemDeclarationData;7
1BN22IN prisoner CLASS V SP
U0010000004
prisoner CLASS V SP
1
1
26
-1
0
0
0
0
0
Type: SupplyLoad;4
0
0
end;
end;
The output would then look something like this:
Type: SystemDeclarationData;7
100000056
U0010000003
prisoner VIII SP
1
1
25
-1
0
0
0
0
0
Type: SupplyLoad;4
0
0
end;
end;
Type: SystemDeclarationData;7
20000056
U0010000004
prisoner CLASS V SP
1
1
26
-1
0
0
0
0
0
Type: SupplyLoad;4
0
0
end;
end;
Notice that only the "prisoner" string underneath the "Type: SystemDeclarationData;7" string changed.
The .csv file will end up being either a one or two column file depending on whether or not they want names along with the numbers.
I don't know if that helps or not. don't have much to contribute as far as a real sample goes at the moment. They pretty much gave me basic structure, a goal, and said have fun. heh.
---------- Post updated at 01:03 PM ---------- Previous update was at 12:05 PM ----------
Frans:
We are on the right track!! I modified the scropt that you posted a little bit:
#!/bin/bash
changefile="test_csv.csv" #this is the file the new string is pulled from
Input="test.fplan" #this is the file that needs changed
I=1
while read LINE
do #~ find the string that starts with data7
if [[ "${LINE}" =~ "SystemDeclarationData" ]]
then
read LINE #~ if the string on the next line has the word prisoner then replace it with the string in line 1.
if [[ "${LINE}" =~ "JDLM" ]]
then
head -n$I "$changefile" | tail -n1
(( I ++ )) #~ the next instance of the pattern would be replaced by the string in line 2 and so on.
else echo "$LINE"
fi
else echo "$LINE"
fi
done < "$Input" > /home/bj/Desktop/test_complete
The only problem i'm having is that it's deleting the line that contains "SystemDeclarationData". otherwise it's working great. can you tell me what i'm doing wrong?