Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter a text file into a new text file

Sorry about the dummy question here.

Under Windows I would like to be able to filter one .txt file into a new one. Filtering all lines that contain a specific string.

I know this could well be a really easy one, but would really appreciate a few pointers please.

like image 473
Strontium_99 Avatar asked Nov 28 '11 14:11

Strontium_99


2 Answers

Use the findstr command:

findstr my-string filename > new-file

findstr /? will give you a usage message telling you how to use findstr (including the /V switch if you wanted to filter lines out rather than filtering them in.)

Or if you're familiar with grep and wishing you had it on Windows, install Cygwin. :-)

like image 157
RichieHindle Avatar answered Sep 18 '22 21:09

RichieHindle


Powershell has some neat string comparison features. You can pipe the output to a new file.

^^ There are some better links as to how to use Powershell - but I can't find them this minute. If you go the Powershell route there are lots of examples on the internet.

like image 30
Neil Thompson Avatar answered Sep 17 '22 21:09

Neil Thompson