1

I have 3 text files containing 10 lines each:

Text1:

01-TextA
02-TextA
03-TextA
04-TextA
05-TextA
06-TextA
07-TextA
08-TextA
09-TextA
10-TextA

Text2:

01-TextB
02-TextB
03-TextB
04-TextB
05-TextB
06-TextB
07-TextB
08-TextB
09-TextB
10-TextB

Text3:

01-TextC
02-TextC
03-TextC
04-TextC
05-TextC
06-TextC
07-TextC
08-TextC
09-TextC
10-TextC

how can I assemble Line 1 of text1 + Line 1 of text2 + Line 1 of text3, etc.. inside a new text file? it should look like that:

01-TextA
01-TextB
01-TextC
02-TextA
02-TextB
02-TextC
03-TextA
03-TextB
03-TextC
04-TextA
04-TextB
04-TextC
05-TextA
05-TextB
05-TextC
dbenham
  • 127,446
  • 28
  • 251
  • 390
Volvo
  • 13
  • 3

3 Answers3

1

Hope this what you want to get with this code :

@echo off
set "File1=Text1.txt"
set "File2=Text2.txt"
set "File3=Text3.txt"
Set "OutPutFile=%~dp0OutPut.txt"
If Exist "%OutPutFile%" Del "%OutPutFile%"
set /a count1=0
set /a count2=0
set /a count3=0
SETLOCAL enabledelayedexpansion
for /F "tokens=* delims=" %%a in ('Type "%File1%"') do (
         Set /a count1+=1
         Set "LineTxt1[!count1!]=%%a"     
)

for /F "tokens=* delims=" %%b in ('Type "%File2%"') do (
         Set /a count2+=1
         Set "LineTxt2[!count2!]=%%b"     
)

for /F "tokens=* delims=" %%c in ('Type "%File3%"') do (
         Set /a count3+=1
         Set "LineTxt3[!count3!]=%%c"     
)

For /L %%i in (1,1,%Count1%) Do (
    Call :Write !LineTxt1[%%i]! !LineTxt2[%%i]! !LineTxt3[%%i]!
)
Start "" "%OutPutFile%"
Exit
::*******************************************************
:Write
(
    echo %1 
    echo %2
    echo %3
)>>"%OutPutFile%"
exit /b
::*******************************************************

The Output is like this :

01-TextA 
01-TextB
01-TextC
02-TextA 
02-TextB
02-TextC
03-TextA 
03-TextB
03-TextC
04-TextA 
04-TextB
04-TextC
05-TextA 
05-TextB
05-TextC
06-TextA 
06-TextB
06-TextC
07-TextA 
07-TextB
07-TextC
08-TextA 
08-TextB
08-TextC
09-TextA 
09-TextB
09-TextC
10-TextA 
10-TextB
10-TextC
Hackoo
  • 18,337
  • 3
  • 40
  • 70
0

Personally I would use python to read the json files and start by creating 3 lists, each list being one of the original json files.

json1_file = open('json1')
json1_str = json1_file.read()
... Same for json2
... Same for json3

Then create your final list and iterate each list's elements 1 level at a time like below.

final_list = [] 

for i in range(0,len(int(json1_str))):
    final_list[].append = json1_str[i]

Or something along those lines. Apologies if this doesn't format right or if there is any errors in the code currently however I'm on my phone. I will update with correct code if this doesn't work however I thought this might atleast get you on the right track initially.

skillsmuggler
  • 1,862
  • 1
  • 11
  • 16
  • Thank you for your answer, but I do not know the Python language. Do you think there would be an easier way to do it? Like an excel script, or a windows batch file? – Volvo Oct 10 '19 at 23:19
  • I would say python will be the easiest way... If this kind of thing is something you are involved with learning the basics of python will be really handy. There is a lot of info online to walk through everything. I've used VBA and Python previously and they're both great for this kind of task but from experience python is and was easier to learn, use and faster to get the desired outcome. – Benjamin Nicholas Oct 10 '19 at 23:24
  • You could other than learning python, convert the json files to CSV online then use excel? – Benjamin Nicholas Oct 10 '19 at 23:26
0

in cmd window (or bat file )type

copy text1 + text2 + text3 text4
type text4 | sort > text5

You will receive sorted file text5

yu2
  • 126
  • 4
  • The content of the 3 text files is not fixed and may vary. it would be dependent on text1.txt + text2.txt + text3.txt – Volvo Oct 10 '19 at 23:30
  • In any case you will receive file 5, in which you will get all lines from files 1,2,3 in sorted order – yu2 Oct 10 '19 at 23:36
  • I do not understand how to do what you explain. I have 3 files: text1.txt, text2.txt and text3.txt – Volvo Oct 10 '19 at 23:47
  • Open cmd window. type on keyboard: `copy text1 + text2 + text3 text4` press Enter type on keyboard: `type text4 | sort > text5` press Enter that's it – yu2 Oct 11 '19 at 02:18