topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 13, 2024, 3:25 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: extract lines containing  (Read 9128 times)

kalos

  • Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 1,824
    • View Profile
    • Donate to Member
extract lines containing
« on: September 23, 2013, 04: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
    • View Profile
    • Donate to Member
Re: extract lines containing
« Reply #1 on: September 23, 2013, 07:43 PM »
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

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 888
  • what am I doing in this handbasket?
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: extract lines containing
« Reply #2 on: September 23, 2013, 07:45 PM »
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: extract lines containing
« Reply #3 on: September 24, 2013, 12: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.

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
Re: extract lines containing
« Reply #4 on: September 24, 2013, 01: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:

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 :

Along the way, qgrep somehow changed its name to findstr.
http://blogs.msdn.co.../11/28/10372436.aspx
.
« Last Edit: September 24, 2013, 01:28 AM by AbteriX »

David1904

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 43
    • View Profile
    • Donate to Member
Re: extract lines containing
« Reply #5 on: September 25, 2013, 04: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
  • *
  • default avatar
  • Posts: 4
    • View Profile
    • Donate to Member
Re: extract lines containing
« Reply #6 on: October 24, 2013, 05: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
  • ***
  • default avatar
  • Posts: 19
    • View Profile
    • Donate to Member
Re: extract lines containing
« Reply #7 on: December 16, 2013, 04:58 PM »
http://textmechanic.com/ online text manipulation tool

alandavid

  • Participant
  • Joined in 2013
  • *
  • Posts: 1
    • View Profile
    • Donate to Member
Re: extract lines containing
« Reply #8 on: December 17, 2013, 12: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.