K
Kevin
Guest
Kevin Asks: How do can I grab everything from the first occurrence of Grid-ref to the last bit from a file which contains the data in the format below in js
I am learning to code in javascript and I have been task to extract data from a .pre text file which looks like below and insert the data into a 4 columned DB table which looks like this Xref Yref Date Value Xref is the value 1 from the Grid-ref= 1, 148 line etc Yref is the value 148 from the Grid-ref= 1, 148 line etc date is in the format 1/1/1991 where the first row of values represents Jan 1991 to Dec 1991, the second row Jan 1992 to Dec 1992 etc. value is the corresponding value like this row 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 I have written this code to read the file and sort of display it as an array, I now want to grab the bit of the file from the first occurrence of Grid-Ref to the bottom of the over 50,000 rows and then pull/transfer the data into the DB table format described above
I know how to create my own DB and use node js to get, pull, put, delete etc. What i am struggling with is the transform this data into the DB grabbing the correct bits using regex or something similar. You help will be greatly appreciated
I am learning to code in javascript and I have been task to extract data from a .pre text file which looks like below and insert the data into a 4 columned DB table which looks like this Xref Yref Date Value Xref is the value 1 from the Grid-ref= 1, 148 line etc Yref is the value 148 from the Grid-ref= 1, 148 line etc date is in the format 1/1/1991 where the first row of values represents Jan 1991 to Dec 1991, the second row Jan 1992 to Dec 1992 etc. value is the corresponding value like this row 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 I have written this code to read the file and sort of display it as an array, I now want to grab the bit of the file from the first occurrence of Grid-Ref to the bottom of the over 50,000 rows and then pull/transfer the data into the DB table format described above
I know how to create my own DB and use node js to get, pull, put, delete etc. What i am struggling with is the transform this data into the DB grabbing the correct bits using regex or something similar. You help will be greatly appreciated
Code:
Some sample text is here
.pre = precipitation (mm)
CRU TS 2.1
[Long=-180.00, 180.00] [Lati= -90.00, 90.00] [Grid X,Y= 720, 360]
[Boxes= 67420] [Years=1991-2000] [Multi= 0.1000] [Missing=-999]
Grid-ref= 1, 148
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
Grid-ref= 1, 311
490 290 280 230 200 250 440 530 460 420 530 450
490 290 280 230 200 250 440 530 460 420 530 450
490 290 280 230 200 250 440 530 460 420 530 450```
SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.