DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: extract lines containing  (Read 12,323 times)

kalos

  • Member
  • Joined in 2006
  • **
  • Posts: 1,824
extract lines containing
« on: September 23, 2013, 09:55 PM »
hello
can you tell me please how to search inside a bunch of text files and "extract'' all the lines that contain *something* in a list into a new text file?
thanks!

AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
Re: extract lines containing
« Reply #1 on: September 24, 2013, 12:43 AM »
from a command line you can issue the Find command and redirect the results to a text file

if you want to use wildcards I think you have to use the Find command inside a For statement

look up Find, For, and redirecting output in a Command Line reference

x16wda

  • what am I doing in this handbasket?
  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 888
    • Participated in NANY Challenge Once
Re: extract lines containing
« Reply #2 on: September 24, 2013, 12:45 AM »
Quote
qgrep -y findme *.txt > results.txt

That's on a Windows platform with qgrep (from one of the old resource kits).  The -y means case insensitive, findme is the string to find (you could look for multiple words with "one two" instead, it will find lines with either), you're searching through all the .txt files and directing the output to a file.

Of course there are more options with a real grep, depending on your platform.
vi vi vi - editor of the beast

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: extract lines containing
« Reply #3 on: September 24, 2013, 05:19 AM »
grepWin

2013-09-24 15_18_13-grepWin _ D__My Documents.png

1) Directory
2) Text search
3) Text to search for
4) File filter
5) Select to display Content

When it's finished, select all the results and copy to clipboard, you can then paste them into a file.
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

AbteriX

  • Member #520
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,150
Re: extract lines containing
« Reply #4 on: September 24, 2013, 06:11 AM »
from a command line you can issue the Find command and redirect the results to a text file

if you want to use wildcards I think you have to use the Find command inside a For statement

look up Find, For, and redirecting output in a Command Line reference

Nowadays we even have 'findstr' on Win7:

Code
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P]
        [/F:Datei] [/C:Zeichenfolge] [/G:Datei] [/D:Verzeichnisliste]
        [/A:Farbattribute] [/OFF[LINE]] Zeichenfolgen
        [[Laufwerk:][Pfad]Dateiname[ ...]]
http://ss64.com/nt/findstr.html


C:\>FindStr /R myregexsearchpattern C:\Temp\*.txt > C:\Temp\results.txt


- - -

hehehe, the circle closes  :P :

Quote
Along the way, qgrep somehow changed its name to findstr.
http://blogs.msdn.com/b/oldnewthing/archive/2012/11/28/10372436.aspx
.
Greetings, Stefan.
« Last Edit: September 24, 2013, 06:28 AM by AbteriX »

David1904

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 43
Re: extract lines containing
« Reply #5 on: September 25, 2013, 09:42 PM »
Available on TUCOWS

TextHarvest 3.00.00
file size: 696.39 KB

As TextHarvest copies a text file it can keep, delete, skip, edit or reformat lines that contain specified strings of text.

saralynn

  • Participant
  • Joined in 2013
  • *
  • Posts: 4
Re: extract lines containing
« Reply #6 on: October 24, 2013, 10:25 PM »
TextPad has a "Find in Files" command that lets you search content of files within your specified path.
Search pattern can be a regular expression & you can limit which type(s) of files are searched.
Although it doesn't directly export the search results to a new file, you can easily SaveAs the results output.
(you'll probably first want to search/replace to remove the filename+lineNumber from start of each line)

ur1sn00per

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 19
Re: extract lines containing
« Reply #7 on: December 16, 2013, 10:58 PM »
http://textmechanic.com/ online text manipulation tool

alandavid

  • Participant
  • Joined in 2013
  • *
  • Posts: 1
Re: extract lines containing
« Reply #8 on: December 17, 2013, 06:57 AM »
grepWin
(see attachment in previous post)
1) Directory
2) Text search
3) Text to search for
4) File filter
5) Select to display Content

When it's finished, select all the results and copy to clipboard, you can then paste them into a file.
Thanks for share such a good information. i am new in this but now i got it.

Original address: https://www.donationcoder.com/forum/index.php?topic=36193.0