Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Script that extras lines from .txt file based on character count and phrases

I have a large .txt file that I need to scan through to extrapolate certain lines of text from. I want to extract all lines that contain X amount of characters, and a certain phrase. How can I go about doing this?
Code
with open('data.txt') as f:
   for line in f.readlines():
       if len(line) > 5 and 'some_word' in line:
           print(line)
(Jun 8, 2019 01:36 PM)michalmonday Wrote:  
Code
with open('data.txt') as f:
   for line in f.readlines():
       if len(line) > 5 and 'some_word' in line:
           print(line)

It would probably be better to use some sort of regular expression for this.

¸„»°'´¸„»°'´Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´
(Jun 9, 2019 02:12 PM)vorticalbox Wrote:  It would probably be better to use some sort of regular expression for this.

dont think so as he want the lines not the regex
the example posted is the simple way to do it
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP


Possibly Related Threads...
Thread / Author Replies Views Last Post
by RonyKingSourcingMay 14, 2024 10:37 PM 2 219 May 14, 2024 10:37 PM
Last Post: RonyKingSourcing
[.NET] by MarwenSep 24, 2022 04:19 PM 10 638 Sep 24, 2022 04:19 PM
Last Post: BinaryFox
[Python] by Mr. RobotSep 11, 2022 12:33 AM 1 156 Sep 11, 2022 12:33 AM
Last Post: 570RM