Click here for important information about Computing.net.

Solved Batch file to copy some lines of txt

December 1, 2020 at 06:54:51
Specs: Windows 10
Hello. I have some folders (test1, test2 etc) each one containing one file called node.txt. I would like to copy some of the lines of each node.txt in another file (finaldata.txt). The aim is to have one file (finaldata.txt) contining lines 11-17 (out of 18) of each node.txt in sequential order.

Someone can help me?

Thanks


See More: Batch file to copy some lines of txt


✔ Best Answer
December 2, 2020 at 23:48:12
:: 1117.bat 2020-12-03 14:27:18.52
@echo off > OUT.TXT & setLocal enableDELAYedeXpansioN
> IN.TXT dir/b/s node.txt
:main
for /f "tokens=* delims= " %%a in (IN.TXT) do (
call :sub1 %%a
) >> OUT.TXT
goto :eof

:sub1
set N=
for /f "tokens=* delims= " %%i in (%1) do (
set/a N+=1
if !N! geq 11 if !N! leq 17 echo.%%i
)
goto :eof
::====== script ends here =================

=====================

M2



#1
December 1, 2020 at 18:28:15
Let me try to send this to the 'programming' forum where the smart people hang out.

Reply ↓  Report •

#2
December 1, 2020 at 23:16:36
Thanks, let me know!

Reply ↓  Report •

#3
December 2, 2020 at 00:38:46
Well, they haven't moved it yet. If they don't by tomorrow you may want to just make a new posting there.

Reply ↓  Report •

Related Solutions

#4
December 2, 2020 at 18:14:29
mebbe:
:: ---------- script start
@echo off & setlocal
for /f "tokens=*" %%a in ('dir /b /s node.txt') do more +11 %%a >>finaldata.txt
::---------- script end
This still leaves one line per file, all lines 18, in the accumulator file, that needs to be removed or replaced. Run script from the root of all the test- files.

message edited by nbrane


Reply ↓  Report •

#5
December 2, 2020 at 23:48:12
✔ Best Answer
:: 1117.bat 2020-12-03 14:27:18.52
@echo off > OUT.TXT & setLocal enableDELAYedeXpansioN
> IN.TXT dir/b/s node.txt
:main
for /f "tokens=* delims= " %%a in (IN.TXT) do (
call :sub1 %%a
) >> OUT.TXT
goto :eof

:sub1
set N=
for /f "tokens=* delims= " %%i in (%1) do (
set/a N+=1
if !N! geq 11 if !N! leq 17 echo.%%i
)
goto :eof
::====== script ends here =================

=====================

M2


Reply ↓  Report •

Ask Question