Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i have a text file with about 2000 lines. how can i sort the lines (based on first alphabet in each line) and then extract block of text starting from (A to M) and (N to Z)? that means there will be 2 output files, one containing all text lines starting from A upto M and the other containing all text lines starting from N upto Z.
thanks
sushilraina

First part. Say your file is called mixed.txt
sort mixed.txt > sorted.txt
Second part
findstr "^[A-M]" sorted.txt > ATOM.txt
findstr "^[N-Z]" sortex.txt > NTOZ.txt

Hi cup,
good one
=====================================
If at first you don't succeed, you're about average.M2

cup, thanks a lot for your answer. it helped me a lot to solve my problem and i learned a lot from it.
i renamed my batch file "cup.bat" after using your hint.
thanks,
sushilraina

Is there a way by which we can extract few lines from a text file based on a condition.
E.g A file has 2000 lines and we would like to search for word "internet". Once this word is found, we need 10 lines before and after this word.
Thanks
Supreet Arora

I'm amazed you were able to post a reply in a thread this old.
I recommend a new one. In case the magic wears off.
::==================================
If the keyword occurs only once::::==
:: get 10 lines before and fter keyword@echo off > newfile
setLocal EnableDelayedExpansionfor /f "tokens=1 delims=[]" %%a in ('find /n "internet" ^< biglog') do (
set /a K=%%a
)set /a S=!K!-10
set /a E=!K!+10for /f "tokens=* delims= " %%i in (biglog) do (
set /a N+=1
for /L %%L in (!S! 1 !E!) do (
if !N! equ %%L echo %%i >> newfile
)
)
=====================================
If at first you don't succeed, you're about average.M2

How about multiple instance of word “start” and “end” in a file? But each set of start and end needs to be outputted to a single file. For instance start1 goes with end1, etc. start1 and end1 doesn’t have a consistent location in the file. Pretty much what I need is to separate multiple files (identified by the start and end) inside a single file.
G2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |