jordan.peoples jordan.peoples - 14 days ago 6
Bash Question

How to read file names from a txt file in cmd prompt(script) and then combine a subset of the files into a PDF file using the cmd line in windows

I have a text file in the following format:

2014-05-13 03:35 PM 48,841 SUR2-**C01**-00-000-PCE-1001-002.pdf
2014-05-13 03:36 PM 43,599 SUR2-**C01**-00-000-PCE-1002-001.pdf
2014-05-13 03:35 PM 51,900 SUR2-**C02**-00-000-PCE-1000-001.pdf
2014-05-13 03:35 PM 53,622 SUR2-**C02**-00-000-PCE-1000-002.pdf
2014-05-13 03:35 PM 52,145 SUR2-**C02**-00-000-PCE-1000-003.pdf
2014-05-13 03:35 PM 50,426 SUR2-**C02**-00-000-PCE-1000-004.pdf


I need to parse this file, and pull out files that match C01 or C02, and send these files to a combined PDF file, one for C01 and one for C02.

How can i parse the file, and string match the file names on C01 or C02?

Then, how can i take the above parse result, and using the file names found, combine them into a PDF from the command line or in script?

Answer

merge-C01.bat

1.use awk to parse the file to array

set LIST=($(awk '/C01/{print $5}' file.txt))

2.use pdf merge tool (pdftk) to merge files in array

for %%i in %LIST% do pdftk out.pdf %%i cat output out.pdf