I have I alrdy looked at this question: How to replace substrings in windows batch file And also this one ; How can you find and replace text in a file using the Windows command-line environment? My problem is around this : How to pass path with spaces to script for when I search for a specific string within my CSV file, which contains folder path location I get the error below ; listed under ERROR . My end goal is to just get from sample data 1415, 1417 and 1419. BUT I'm willing to do 2 bat file; powershell file calls if it gets me there. My code in BAT FILE is as following
powershell -ExecutionPolicy ByPass -File C:\Users\xyz\Desktop\bat_file_compare_TEST\step_3_Replace_extra_data_with_just_Store_no.ps1
pause
and my code in powershell called by BAT file above is . Error is after this and depending on if i use single quotes vs double my error is right around replace. (2) I have also tried "gc" instead of get-content. (3) no quotes around the somereport_generated_store_filenames.csv .
powershell -Command "(Get-Content 'C:\Users\xyz\Desktop\bat_file_compare_TEST\somereport_generated_store_filenames.csv') -replace 'C:\Users\xyz\Desktop\bat_file_compare_TEST\somereport_generated_files\somereport-', 'test' | Out-File 'C:\Users\xyz\Desktop\bat_file_compare_TEST\somereport_generated_store_filenames_just_Store_no.csv' -encoding ASCII"
Error:-
The regular expression pattern C:\Users\xyz\Desktop\bat_file_compare_TEST\somereport_generated_files\somereport is not valid.
At line:1 char:1
+ (Get-Content 'C:\Users\xyz\Desktop\bat_file_compare_TEST\somereport_genera ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (C:\Users\xyz\...rated_files\somereport:String) [], RuntimeException
+ FullyQualifiedErrorId : InvalidRegularExpression
Finally Sample Data if anyone wishes to re-create this is:
C:\Users\xyz\Desktop\bat_file_compare_TEST\somereport_generated_files\somereport-2022M01-1415.pdf
C:\Users\xyz\Desktop\bat_file_compare_TEST\somereport_generated_files\somereport-2022M01-1417.pdf
C:\Users\xyz\Desktop\bat_file_compare_TEST\somereport_generated_files\somereport-2022M01-1419.pdf