Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8113589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:52:37+00:00 2026-06-06T02:52:37+00:00

I have a file which I’m trying to extract information from, the file has

  • 0

I have a file which I’m trying to extract information from, the file has the information in it and is in a neat line by line format, the information is separated by commas.

I want to put it in a list, or do whatever I can to extract information from a specific index. The file is huge with over 1000000000 lines, I have to extract the same index in every line in order to get the same piece of information. These are HASHES I want from the files so I was wondering how I’d find all the occurrences of hashes based on length.

import os

os.chdir('C:\HashFiles')

f = open('Part1.txt','r')

file_contents=f.readlines()

def linesA():

for line in file_contents:
    lista = line.split(',')

print linesA()

this is all I have so far and this just puts everything in a list which I can index from, but I want to output the data from those indexes to another file and I am unable to because of the for statement, how can I get around this?

Wow you guys are great, now I have a problem because in the file where this info is stored it starts with information about the sponsor who provided the information, how do I bypass those lines to start from another line since the lines I need start at about 100 lines down the file, to help me because at the moment I get an index error and am unable to figure out how to set a condition to counter it. I tried this condition but didnt work : if line[:] != 15: continue

Most recent code to work with:

import csv

with open('c:/HashFiles/search_engine_primary.sql') as inf, open('c:/HashFiles/hashes.txt','w') as outf:
for i in xrange(47):
    inf.next()       # skip a line

for line in inf:
    data = line.split(',')
    if str(line[0]) == 'GO':
        continue
    hash = data[15]
    outf.write(hash + '\n')
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:52:40+00:00Added an answer on June 6, 2026 at 2:52 am

    You can process the file line-by-line, like so:

    with open('c:/HashFiles/Part1.txt') as inf, open('c:/HashFiles/hashes.txt','w') as outf:
        for line in inf:
            data = line.split(',')
            hash = data[4]
            outf.write(hash + '\n')
    

    If you want to separate the hashes by length, maybe something like:

    class HashStorage(object):
        def __init__(self, fname_fmt):
            self.fname_fmt = fname_fmt
            self.hashfile = {}
    
        def thefile(self, hash):
            hashlen = len(hash)
            try:
                return self.hashfile[hashlen]
            except KeyError:
                newfile = open(self.fname_fmt.format(hashlen), 'w')
                self.hashfile[hashlen] = newfile
                return newfile
    
        def write(self, hash):
            self.thefile(hash).write(hash + '\n')
    
        def __del__(self):
            for f in self.hashfiles.itervalues():
                f.close()
            del self.hashfiles
    
    store = HashStorage('c:/HashFiles/hashes{}.txt')
    
    with open('c:/HashFiles/Part1.txt') as inf:
        for line in inf:
            data = line.split(',')
            hash = data[4]
            store.write(hash)
    

    Edit:: is there any way to identify sponsor lines – for example, they start with “#”? You could filter like

    with open('c:/HashFiles/Part1.txt') as inf, open('c:/HashFiles/hashes.txt','w') as outf:
        for line in inf:
            if not line.startswith('#'):
                data = line.split(',')
                hash = data[4]
                outf.write(hash + '\n')
    

    otherwise, if you have to skip N lines – this is nasty, because what if the number changes? – you can instead

    with open('c:/HashFiles/Part1.txt') as inf, open('c:/HashFiles/hashes.txt','w') as outf:
        for i in xrange(N):
            inf.next()       # skip a line
    
        for line in inf:
            data = line.split(',')
            hash = data[4]
            outf.write(hash + '\n')
    

    Edit2:

    with open('c:/HashFiles/search_engine_primary.sql') as inf, open('c:/HashFiles/hashes.txt','w') as outf:
        for i in xrange(47):
            inf.next()       # skip a line
    
        for line in inf:
            data = line.split(',')
            if len(data) > 15:      # skip any line without enough data items
                hash = data[15]
                outf.write(hash + '\n')
    

    Does this still give you errors??

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file which has contents on every line following this format (A,
I have a file which has multiple columns, whitespace separated. e.g: data1 data2 data3
I have a file which has data in the following format A B -----
I have a file which has absolute filepaths listed, 1 per line. The listed
I have a file which has contents in the following format: string1 = string2.a
I have a file which has about 25000 lines, and it's a s19 format
I have a file which contains lines of data in the following format: a11
I have a file which may be in ASCII or UTF-8 format. I can
I have a file which contains lines of the following format: w1#1#x w2#4#b w3#2#d
I have a file which has multiple lines. It is required to have -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.