I am complete new in writting powershell scripts. So far I was using plain batch for my purpose as this is the requirement by my company. Inside this batch I am using nested foor loops to make a comparison of two .txt files, in detail I wantdo do the following:
- File 1 contains lots of strings. Each string is in one seperate line with a preceded number and semicolon like so:
658;RMS
- File 2 is some long text.
The aim is to count the amount of occurences of each string from File 1 in File 2, e.g. RMS is counted 300 times.
As my previous code hase some huge drawbacks concerning runtime (File 1 has approx. 400 lines and File 2 500.000) I read that the Select-String from Powershell is much more efficient. However, as I am reading some tutorials it is not clear to me how I can proceed here, beside that I have to run the powershellcode inside my .bat. My biggest problem is I am not sure how and where to place my 'variables', so the two inputfiles 1 and 2
So far I was testing the Select-String method like this:
powershell -command "& {Select-String -Path *.txt -Pattern "RMS"}"
My assumption would be to make use of piping, so something like this:
powershell -command "& {<<path to file one, should read line by line>> | Select-String -Path File2.txt -Pattern "value of file 1"}"
However, I am not getting this to work. Powershell is excpecting some kind of psobject
before the first pipe?