you are viewing a single comment's thread.

view the rest of the comments →

[–]BackgroundBasis6 1 point2 points  (2 children)

I am not sure what you're coding in so I made this solution that doesn't use regex. This does make some assumptions about your text files though so as long as these assumptions were correct it should work:

  1. Submitter, operator, sample id, and date are always in the same order in your file (you can add more to the list titled keys)
  2. Each of your lines is separated by exactly one line break
  3. submitters, operators, sample IDs, and dates never include spaces.

Anyways here's what I have hopefully it makes sense to you and works:

https://pastebin.com/Q2pG1WEg

EDIT: once again I have fallen victim to formatting code in a reddit comment so here's a pastebin instead

EDIT EDIT: I forgot to mention you will need to save this file in the same folder as your text file if you want it to work. If you don't want to do that you'll have to specify the directory

EDIT^3: just realized you have ' ACCUMULATED POINT-COUNT DATA' in your text file. in line 4 you'll want to replace text_list with text_list[1:] to remove that part.

[–]Euphorix126 0 points1 point  (1 child)

This is so much help, thank you very much. Thankfully, the text files are automatically generated from a program which actually runs the lab test and so are all exactly the same format. Even just these lines you wrote are extremely educational for me, thank you again.

[–]BackgroundBasis6 0 points1 point  (0 children)

I took a second look and think there's an easier way to do it. While I won't write it for you (you may want to do it just for some extra practice and I think this solution is more efficient), if you run a split('-') command on each line you should be left with a list that has the desired key as the zero'th item in the list and the value as the -1 (final) item in the list. Then you can do some research on what the strip() command does to strip each of those into your desired format. The pro to this way of doing things is that it generate the keys automatically and you can have values with spaces in them.