Extract Strings from a text file into another text file? In .bat

Viewed 2089

I have a text file that contains names of all the files in my directory followed by its date.

Is it possible in batch/bash to extract those files names from the text file and its date based on a value on the string.

I have already checked Extracting strings from text file but this does not answer my query. I have also checked numerous others including Get specific string from a text file using batch command and seems to hit a dead end as it doesn't get all the lines from the whole text file.

a typical string/file name looks like this

5f367f72-9e2f-4f89-b3d6-2cdafed17d94_IRO_RMUSI_SONG_TimayaKingPerryy_KomKom.mxf_A1.MXF,25/07/2019 05:47:24

The identifier is IRO. i have more files in the text file as well but I want it to be able to look at the text file, find everything that has the identifier and make a new text file with the IRO file and date populated.

There are about 150,000 +/- line of string so manually doing this wont be easy.

If its possible to be done in a batch-file i would appreciate it.

1 Answers

That's quite easy if you think about it. Filter your file with findstr "_IRO_"), then split the filename from the date with a for /f loop (according to your example, they are delimited with a comma):

(for /f "delims=," %%a in ('type "names.txt" ^|findstr "_IRO_"') do @echo %%a) > "newnames.txt"

Note: to execute it directly from a command line instead of in a batch file, replace every %%a with %a.

Related