I need to take the input of each row from the 'input_file.txt' column 'data1' and change the value of 'PH' in the main_file.txt and input of each row from the 'input_file.txt' column 'data2' and change the value of 'BULKD' in the main_file.txt. After changing values in the main_file.txt with the input from each row of the input_file.txt one file will be created like, main_file_1.txt (for row 1); main_file_2.txt (for row 2) and so on......
i could not understand how to start the algorithm for this program. any help will be highly appreciated!!
A pointer == another pointer only if they hold the same address. One pointing to string literal means automatics failure. std::string is your friend.
You do have other logical issues too.
If you would just want the job done, rather than to use C++ or to learn programming, you could:
let NUM=0
while read data1 data2 dum
do if [[ "${data1}" != "data" ]]
then let NUM=${NUM}+1
sed "s/^.* 'PH'/${data1} 'PH'/; s/^.* 'BULKD'/${data2} 'BULKD'/" main.txt > out_${NUM}.txt
fi
done < input.txt
With C++ one could do:
1. Read main.txt into a std::vector< std::pair< std::string, std::string > >
2. Create iterators to the two elements (PH and BULKD) of the vector
3. Open input.txt
4. While input.getline
4a. separate the two std::string data values from line
4b. update the two elements
4c. write vector to out_i.txt