Hack Forums
Exporting specific entries from huge TXT file - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88)
+---- Forum: Computing Lounge (https://hackforums.net/forumdisplay.php?fid=8)
+---- Thread: Exporting specific entries from huge TXT file (/showthread.php?tid=5999204)



Exporting specific entries from huge TXT file - focuss - Aug 14, 2019

Does anyone know how to export specific entries from a huge txt file?
For example, I want to export each line to another txt file if they do not include hotmail, gmail, etc
I can do this in excel but there a too many lines for excel to handle so I want to export to a new txt file and manage it from there.


RE: Exporting specific entries from huge TXT file - MavenGradle - Aug 14, 2019

If you can manage it in Excel but the text file is too large, why not split the text file?


RE: Exporting specific entries from huge TXT file - datguy.dev - Aug 14, 2019

Read chunks of the file at a given time. Read each line and detect if it contains keywords. Easy stuff. If you want to learn how to do that, head over to the Python section for further assistance.

PHP Code

<?php 
def read_in_chunks
(file_object, chunk_size=1024):
    
"""Lazy function (generator) to read a file piece by piece.
    Default chunk size: 1k."""
    
while True:
        
data = file_object.read(chunk_size)
        if 
not data:
            break
        yield 
data


f 
= open('really_big_file.dat')
for 
piece in read_in_chunks(f):
    
process_data(piece) 



RE: Exporting specific entries from huge TXT file - focuss - Aug 15, 2019

(Aug 14, 2019 07:06 PM)datguy.dev Wrote:  Read chunks of the file at a given time. Read each line and detect if it contains keywords. Easy stuff. If you want to learn how to do that, head over to the Python section for further assistance.

Good solution! I was expecting to use PowerShell but Python will do just fine.


RE: Exporting specific entries from huge TXT file - pastort - Sep 16, 2019

Linux command line can do this:

grep -v -i hotmail list.file > withouthotmail.list
or something like:
grep -v -i 'hotmail|gmail|yahoo' > noemails.list