Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch file programming

I tried to copy one file to another from starting line upto a limit. ie., line 1 to 10(file1.txt)->file2.txt but while writing "!" is skipped. what can i do for to solve it. Any help will be thankful.

The loop for that function is given below.

%NF%-> new file.

%EF%-> existing file

%1% -> line number(passed from another part)

:_doit

findstr /N /R "." %EF%|findstr /B /C:"%1:">nul

if errorlevel 1 (    
    echo. >>%NF%        
) else (    
    for /f "tokens=1 delims=" %%a in ('findstr /N /R "." %EF%^|findstr /B /C:"%1:"') do (    
        if [%%a] EQU [] (    
            echo. >>%NF%    
        ) else (    
            echo %%a >>%NF%    
       )     
   )
)
like image 815
Sarika.S Avatar asked Jan 21 '23 09:01

Sarika.S


1 Answers

If you can download tools, you can use GNU win32 gawk

gawk.exe "NR>10{exit}1"  file1 > file2

And you can take a look at this thread here that is similar

like image 176
ghostdog74 Avatar answered Jan 29 '23 05:01

ghostdog74