0

I'm trying to create a quick .bat to sort some data from cards quickly. But I'm wording if its possible to take the data I'm collecting, and have it sorted in excel automatically. If I could have the data separated by commas, it would be simply to convert it to a csv and be done. but the results.txt file sorts it like this:

FN: EXAMPLE A
FN: EXAMPLE B
TITLE: EXAM A
TITLE: EXAM B
ORG: EX A
ORG: EX A

and I want it to look more like

FN: Example A, Example B
Title: EXAM A, EXAM B
ORG: EX A, EX B

Any tips for this?

@Echo off
cd /d %~dp0
copy/B *.vcf all_in_one.vcf
copy/B all_in_one.vcf master_list.txt
(
    findstr /C:"FN:" master_list.txt 
    findstr /C:"TITLE:" master_list.txt
    findstr /C:"ORG:" master_list.txt
    findstr /C:"EMAIL;" master_list.txt
    findstr /C:"TEL;TYPE=WORK:" master_list.txt
)>> results.txt
pause

Edit: Is there a way to transpose the data?

such as:

FN:                      Title:                    Org:
Example A               Exam A                     Ex A
Example B               Exam B                     Ex B
DylanC
  • 15
  • 4

1 Answers1

0

FN: Example A, Example B? I can imagine FN:, Example A, Example B fits your needs better.

@echo off
setlocal 
(for %%z in ("FN:" "TITLE:" "ORG:" "EMAIL;" "TEL;TYPE=WORK:") do (
  <nul set /p ".=%%~z"
  for /f "tokens=1,2 delims=:" %%a in ('type "master_list.txt"^|findstr /bc:"%%~z"') do (
    <nul set /p ".=,%%b"
  )
  echo/
))>results.csv

Pseudo-code:

For each of your search-terms
  write the term without linefeed
  for each match
    find the data and write <comma><matched data>, again without linefeed
  next match
  finish the line
next term

Result with your example input:

FN:, EXAMPLE A, EXAMPLE B
TITLE:, EXAM A, EXAM B
ORG:, EX A, EX A
EMAIL;
TEL;TYPE=WORK:

or as it would look like in EXCEL:

FN:             EXAMPLE A    EXAMPLE B
TITLE:          EXAM A       EXAM B
ORG:            EX A         EX A
EMAIL;
TEL;TYPE=WORK:
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Thank you! I'd hate to impose again, but I made an edit. Could you point me in the right direction? Again, thank you so much! I really appreciate the help! – DylanC Jun 16 '22 at 16:49
  • Not so straightforward with batch Although possible, a [PowerShell solution](https://stackoverflow.com/questions/46351397/transposing-a-csv-file-using-powershell) might be more reliable. – Stephan Jun 16 '22 at 18:06