I have a text file with however many lines. One line is:
fixed_stringA = 123, fixed_stringB = 456
I have a second text file (again with however many lines). These 2 lines are in this order, in middle of the file:
found_value1=unknown1
found_value2=unknown2
My goal is to modify these two lines second text file so that the it will now read:
found_value1=123
found_value2=456
My goal is to do this on the command line without calling another script. The following code works, but I wonder if it can be shortened or improved:
value_variable=$(grep "fixed_stringA = [0-9]*, fixed_stringB = [0-9]*" first_file \
| sed -E 's/fixed_stringA = ([0-9]+), fixed_stringB = ([0-9]+)/\1,\2/'); \
value1=$(echo $value_variable | cut -d "," -f 1); \
value2=$(echo $value_variable | cut -d "," -f 2); \
sed -i -E "s/unknown1/$value1/" second_file.txt; \
sed -i -E "s/unknown2/$value2/" second_file.txt