I'm new to bash scripting and need some help with a project I am working on. I am trying to use bash shell scripting to edit a .txt file with data from a database into a more useful format.
The data is currently in the following format (the file has several thousand pieces of data like this one):
DATA:|11.00000|000563784644|7031450|7031450||1.000000|1.000000|0.000000|0.000000|0.000000|21.000000|47.040000|60.480000|0.000000|0.000000|0.000000|0.000000|0.000000|0.000000|1.000000|100.000000
I would like to remove the "DATA:" prefix from each piece of data in the file, add appropriate date information, and reformat parts of the data to be in the following final format:
2017/01/27|0011|000563784644|7031450|7031450||1|1|0|0.00|0.00|21|47.04|60.48|0|0|0|0 |0.00|0.00|1|100
I have figured out how to iterate over each piece of data in the file like this:
while read p; do
...
done <peptides.txt
But I am struggling with how to modify parts of each 'piece' of data (in a sense, indexing each part by using the '|" as a delimiter).
Would it be best to write a program in C to set each data piece as an array and then work with it, or use bash commands to edit the data strings?