I'm trying to find words in a text file using powershell and print them into another file.Those words do not really have any properties that would distingush them among other words except for the number of the line where each o the word is located. I need data about medications for my study and the data is copied form webpages that look simmilar and the names of the medicine are printed in the same lines every time. This are lines scattered all over text file, containing a single word each one of them, like so many others in there unfortunately.
Here is a smaple text and in this sample I'm interested in copying the names of the medications which in this case are: Amoxicillin, Clindamycin, Azithromycin (lines 6,17,28) and so on, roughly 350 pages, 20 drug names on each...
adm inj500mgFinishedadm injno Amoxicillin 6company logo medication Photo11adm inj500mgFinishedadm injno Clindamycin 17company logo medication Photo2322adm inj128mgAvailableadm injyes Azithromycin 28company logo medication Photo11
I am not a pro coder but what I did was some research and tried this to extract lines with single words (consisting at least two letters - bit proud of my self there) :
$path = Resolve-Path unsoted.txt | Select -Expand Path(Get-Content $path)| Select-String -pattern "^(\w+[a-z]{2})$" -AllMatches | Out-File medications.txt
Of course the result is all wrong becouse of other unwanted lines with unrelated single words, I also found "Select-Object" cdmlet but to me it has no parameters that wuold be suitable for my purpose. I do know how to upload the data and save it, I also understand that PowerShell uses RegEx but after quite an extended research I can not find any advice as to how to do what I need neighter with PS itself nor was I able to find any RegEx instrucion that would find the right lines and grab the words.
Preferred way would by to do it in PowerShell as I have already made plenty effort to make a script that would sort out the data in needed order.Any help will be hugely appreciated,Thank you very much in advanceAll the best