Home > Mobile >  Sorting Words in .txt for excel
Sorting Words in .txt for excel

Time:06-18

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

CodePudding user response:

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:
  • Related