Computing.Net > Forums > Programming > Extract Lines from a Text File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Extract Lines from a Text File

Reply to Message Icon

Name: thomk
Date: January 3, 2006 at 06:40:24 Pacific
OS: Win2000
CPU/Ram: P4 1.7 2GB RAM
Comment:

Very simple:

I'm trying to extract particular lines from a small text file.

Ideally using the Windows command line to take lines 1 and 10 from one text file and output them to another text file.

Thanks!




Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: January 3, 2006 at 07:16:03 Pacific
Reply:

Is there any specific word or pattern that identifies each line (that may be different for the first and tenth line)?

If so the job is straightforward, otherwise not so simple.


0

Response Number 2
Name: FishMonger
Date: January 3, 2006 at 08:21:14 Pacific
Reply:

If you want to use a perl command, this would be very easy.

C:\>perl -ne "print if($. == 1 || $. == 10)" c:\src.txt >> dest.txt


0

Response Number 3
Name: Mechanix2Go
Date: January 4, 2006 at 02:12:18 Pacific
Reply:

FM strikes again

;)

If you prefer a batch, try this:

::====Keep1&10.bat
@echo off

if %1'==' echo which file? && goto :eof
set /a lineNUM=1
for /f "tokens=*" %%L in (%1) do call :keeper %%L
goto :eof

:keeper

if %lineNUM%==1 echo %*
if %lineNUM%==10 echo %*
set /a lineNUM+=1
goto :eof
:: DONE


If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Extract Lines from a Text File

Delete blank lines from a text file www.computing.net/answers/programming/delete-blank-lines-from-a-text-file/14525.html

Copy certain lines from a text file www.computing.net/answers/programming/copy-certain-lines-from-a-text-file/18604.html

Search for a line in a text file www.computing.net/answers/programming/search-for-a-line-in-a-text-file/19293.html