Binayak Chatterjee
Binayak Chatterjee

Reputation: 51

I need a batch script read first line from a text file

I need a batch script read first line from a text file. Then if some line ends with .part1 extension then read the next line. if the next line do not have .part# extension in the end then do some actions with the .part files. So basically those will be urls ending with .part1, .part2 and then I need to download those .part files extract through cmd and some files do not have .part extension.

Example,

new.txt

http://abcd.com/abcd.part1
http://abcd.com/abcd.part2
http://abcd.com/abcd.part3
http://abcd.com/xyz.zip

So I need to download abcd.part1, abcd.part2 and abcd.part3 at once, then extract and delete the part files.

That's what I wanna do

After this point I'm unable to proceed. If someone can just give a code to print all the part files the downloading and unzipping can be done me.

I mean in a sequenced part1..partn I need to print part1..partn

if not found any partn at EOL then print the next line to a file then again search if there's any part file if found print all part1..partn to a file.

@echo off
cd /D %SCP_HOME%
setlocal enableextensions
set count=0
set i=0
for %%x in (*) do set /a count+=1
echo %count%
for /r %%f in (*) do (
    echo %%~nxf
    head 1 %%~nxf
    more +1 %%~nxf > %count%-1%%~nxf
)
endlocal

Upvotes: 1

Views: 1204

Answers (1)

lit
lit

Reputation: 16236

This will iterate over the lines that contain "part*" at the end of the line. Will this get you started?

SETLOCAL ENABLEDELAYEDEXPANSION
SET "THE_FILE=new.txt"

FOR /F "usebackq tokens=*" %%a IN (`TYPE "%THE_FILE%"`) DO (
    ECHO %%~a | FINDSTR /RC:"http://.*\.part[0-9]*" >NUL
    IF !ERRORLEVEL! EQU 0 (
        ECHO This line matches
        ECHO %%~a
    ) ELSE (
        ECHO This line does not match
        ECHO %%~a
    )
)

Upvotes: 1

Related Questions