with open('data.txt', 'r') as f:
    for line in f:
        number = int(line.split(':')[1])
        array.append(number)
print '+'.join(array)

Basically, use the split function to get the number, and then print it as you wish. Please take care of error handling to check if it is integer or not, or if the line has a : or not

Not sure what you mean by shell, but yes you can make a function, and just call a function:

Answer from roymustang86 on Stack Overflow
🌐
John Snow Labs
johnsnowlabs.com › home › the complete guide to information extraction from texts with spark nlp and python
The Complete Guide to Information Extraction from Texts with Spark NLP and Python - John Snow Labs
September 6, 2025 - Information extraction with Spark NLP and Python: TextMatcher, BigTextMatcher, named entity recognition, and scalable NLP pipelines with step-by-step code examples.
🌐
Google Developers
developers.googleblog.com › google for developers blog › introducing langextract: a gemini powered information extraction library
Introducing LangExtract: A Gemini powered information extraction library - Google Developers Blog
July 30, 2025 - Explore LangExtract: a Gemini-powered, open-source Python library for reliable, structured information extraction from unstructured text with precise source grounding.
People also ask

What will I get if I subscribe to this Specialization?
When you enroll in the course, you get access to all of the courses in the Specialization, and you earn a certificate when you complete the work. Your electronic Certificate will be added to your Accomplishments page - from there, you can print your Certificate or add it to your LinkedIn profile.
🌐
coursera.org
coursera.org › browse › data science › machine learning
Applied Information Extraction in Python | Coursera
When will I have access to the lectures and assignments?
To access the course materials, assignments and to earn a Certificate, you will need to purchase the Certificate experience when you enroll in a course. You can try a Free Trial instead, or apply for Financial Aid. The course may offer 'Full Course, No Certificate' instead. This option lets you see all course materials, submit required assessments, and get a final grade. This also means that you will not be able to purchase a Certificate experience.
🌐
coursera.org
coursera.org › browse › data science › machine learning
Applied Information Extraction in Python | Coursera
Is financial aid available?
Yes. In select learning programs, you can apply for financial aid or a scholarship if you can’t afford the enrollment fee. If fin aid or scholarship is available for your learning program selection, you’ll find a link to apply on the description page.
🌐
coursera.org
coursera.org › browse › data science › machine learning
Applied Information Extraction in Python | Coursera
🌐
GitHub
github.com › google › langextract
GitHub - google/langextract: A Python library for extracting structured information from unstructured text using LLMs with precise source grounding and interactive visualization. · GitHub
LangExtract is a Python library that uses LLMs to extract structured information from unstructured text documents based on user-defined instructions.
Author   google
🌐
GeeksforGeeks
geeksforgeeks.org › nlp › information-extraction-in-nlp
Information Extraction in NLP - GeeksforGeeks
January 9, 2026 - This function extracts Subject–Verb–Object relations. Returns structured relations as tuples. Python · def information_extraction(doc): matcher = Matcher(nlp.vocab) nsubj identifies the subject of the sentence. aux is optional to handle ...
🌐
Medium
medium.com › john-snow-labs › the-complete-guide-to-information-extraction-from-texts-with-spark-nlp-and-python-c862dd33995f
The Complete Guide to Information Extraction from Texts with Spark NLP and Python | by Gursev Pirge | John Snow Labs | Medium
May 16, 2023 - The Complete Guide to Information Extraction from Texts with Spark NLP and Python Extract Hidden Insights from Texts at Scale with Spark NLP TL;DR: Information extraction in natural language …
Find elsewhere
🌐
Coursera
coursera.org › browse › data science › machine learning
Applied Information Extraction in Python | Coursera
In “Applied Information Extraction in Python,” you will learn how to extract useful information from free-text data, which is a type of string data created when people type. Examples of free-text data include names of people or organizations, location information such as cities and zip codes, or other elements like stock prices or clinical diagnoses.
Top answer
1 of 4
9

This uses dateutil to parse the date (e.g. '11/11/2010 - 09:00am'), and parsedatetime to parse the relative time (e.g. '4 hours later'):

import dateutil.parser as dparser
import parsedatetime.parsedatetime as pdt
import parsedatetime.parsedatetime_consts as pdc
import time
import datetime
import re
import pprint
pdt_parser = pdt.Calendar(pdc.Constants())   
record_time_pat=re.compile(r'^(.+)\s+:')
sex_pat=re.compile(r'\b(he|she)\b',re.IGNORECASE)
death_time_pat=re.compile(r'died\s+(.+hours later).*$',re.IGNORECASE)
symptom_pat=re.compile(r'[,-]')

def parse_record(astr):    
    match=record_time_pat.match(astr)
    if match:
        record_time=dparser.parse(match.group(1))
        astr,_=record_time_pat.subn('',astr,1)
    else: sys.exit('Can not find record time')
    match=sex_pat.search(astr)    
    if match:
        sex=match.group(1)
        sex='Female' if sex.lower().startswith('s') else 'Male'
        astr,_=sex_pat.subn('',astr,1)
    else: sys.exit('Can not find sex')
    match=death_time_pat.search(astr)
    if match:
        death_time,date_type=pdt_parser.parse(match.group(1),record_time)
        if date_type==2:
            death_time=datetime.datetime.fromtimestamp(
                time.mktime(death_time))
        astr,_=death_time_pat.subn('',astr,1)
        is_dead=True
    else:
        death_time=None
        is_dead=False
    astr=astr.replace('and','')    
    symptoms=[s.strip() for s in symptom_pat.split(astr)]
    return {'Record Time': record_time,
            'Sex': sex,
            'Death Time':death_time,
            'Symptoms': symptoms,
            'Death':is_dead}


if __name__=='__main__':
    tests=[('11/11/2010 - 09:00am : He got nausea, vomiting and died 4 hours later',
            {'Sex':'Male',
             'Symptoms':['got nausea', 'vomiting'],
             'Death':True,
             'Death Time':datetime.datetime(2010, 11, 11, 13, 0),
             'Record Time':datetime.datetime(2010, 11, 11, 9, 0)}),
           ('11/11/2010 - 09:00am : She got heart burn, vomiting of blood and died 1 hours later in the operation room',
           {'Sex':'Female',
             'Symptoms':['got heart burn', 'vomiting of blood'],
             'Death':True,
             'Death Time':datetime.datetime(2010, 11, 11, 10, 0),
             'Record Time':datetime.datetime(2010, 11, 11, 9, 0)})
           ]

    for record,answer in tests:
        result=parse_record(record)
        pprint.pprint(result)
        assert result==answer
        print

yields:

{'Death': True,
 'Death Time': datetime.datetime(2010, 11, 11, 13, 0),
 'Record Time': datetime.datetime(2010, 11, 11, 9, 0),
 'Sex': 'Male',
 'Symptoms': ['got nausea', 'vomiting']}

{'Death': True,
 'Death Time': datetime.datetime(2010, 11, 11, 10, 0),
 'Record Time': datetime.datetime(2010, 11, 11, 9, 0),
 'Sex': 'Female',
 'Symptoms': ['got heart burn', 'vomiting of blood']}

Note: Be careful parsing dates. Does '8/9/2010' mean August 9th, or September 8th? Do all the record keepers use the same convention? If you choose to use dateutil (and I really think that's the best option if the date string is not rigidly structured) be sure to read the section on "Format precedence" in the dateutil documentation so you can (hopefully) resolve '8/9/2010' properly. If you can't guarantee that all the record keepers use the same convention for specifying dates, then the results of this script would have be checked manually. That might be wise in any case.

2 of 4
9

Here are some possible way you can solve this -

  1. Using Regular Expressions - Define them according to the patterns in your text. Match the expressions, extract pattern and you repeat for all records. This approach needs good understanding of the format in which the data is & of course regular expressions :)
  2. String Manipulation - This approach is relatively simpler. Again one needs a good understanding of the format in which the data is. This is what I have done below.
  3. Machine Learning - You could define all you rules & train a model on these rules. After this the model tries to extract data using the rules you provided. This is a lot more generic approach than the first two. Also the toughest to implement.

See if this work for you. Might need some adjustments.

new_file = open('parsed_file', 'w')
for rec in open("your_csv_file"):
    tmp = rec.split(' : ')
    date = tmp[0]
    reason = tmp[1]

    if reason[:2] == 'He':
        sex = 'Male'
        symptoms = reason.split(' and ')[0].split('He got ')[1]
    else:
        sex = 'Female'
        symptoms = reason.split(' and ')[0].split('She got ')[1]
    symptoms = [i.strip() for i in symptoms.split(',')]
    symptoms = '\n'.join(symptoms)
    if 'died' in rec:
        died = 'True'
    else:
        died = 'False'
    new_file.write("Sex: %s\nSymptoms: %s\nDeath: %s\nDeath Time: %s\n\n" % (sex, symptoms, died, date))

Ech record is newline separated \n & since you did not mention one patient record is 2 newlines separated \n\n from the other.

LATER: @Nurse what did you end up doing? Just curious.

🌐
NLTK
nltk.org › book › ch07.html
7. Extracting Information from Text
Typically, these will be definite noun phrases such as the knights who say "ni", or proper names such as Monty Python. In some tasks it is useful to also consider indefinite nouns or noun chunks, such as every student or cats, and these do not necessarily refer to entities in the same way as definite NPs and proper names. Finally, in relation extraction, we search for specific patterns between pairs of entities that occur near one another in the text, and use those patterns to build tuples recording the relationships between the entities.
🌐
arXiv
arxiv.org › abs › 2411.11779
[2411.11779] LLM-IE: A Python Package for Generative Information Extraction with Large Language Models
November 18, 2024 - To address this, we developed LLM-IE: a Python package for building complete information extraction pipelines. Our key innovation is an interactive LLM agent to support schema definition and prompt design.
🌐
arXiv
arxiv.org › html › 2509.20617v1
DELM: a Python toolkit for Data Extraction with Language Models
September 24, 2025 - We introduce DELM, a lightweight, configuration-driven toolkit for building, evaluating, and scaling LLM-based data-extraction pipelines. The framework centers on reproducibility via provenance tracking and deterministic caching, operational reliability through robust batching and retries, and rigorous measurement with schema-aware validation and cost accounting. Case studies demonstrate practical gains in the ease of implementation of information extraction tasks such as estimating cost–recall trade-offs and LLM-in-the-loop prompt optimization.
🌐
Oxford Academic
academic.oup.com › jamiaopen › article › 8 › 2 › ooaf012 › 8071856
LLM-IE: a python package for biomedical generative information extraction with large language models | JAMIA Open | Oxford Academic
March 6, 2025 - Despite the exciting new advancement, at this point, there is no dedicated software to implement it, making the application challenging. Therefore, we publish LLM-IE, an open-source Python package that provides a general framework for LLM-based information extraction (“IE”).
🌐
Towards Data Science
towardsdatascience.com › home › latest › ai-powered information extraction and matchmaking
AI-Powered Information Extraction and Matchmaking | Towards Data Science
February 3, 2025 - In the following article, I demonstrated information extraction from unstructured documents using LLMs. Here, I used python-docx library to extract text from AI consultancy documents (MS WORD) and directly send the text of each document to an LLM for information extraction.
🌐
Analytics Vidhya
analyticsvidhya.com › home › information extraction using python and spacy
Information Extraction using Python and spaCy - Analytics Vidhya
February 15, 2024 - We have a grasp on the theory here so let’s get into the Python code aspect. I’m sure you’ve been itching to get your hands on this section! We will do a small project to extract structured information from unstructured data (text data in our case).
🌐
John Snow Labs
johnsnowlabs.com › home › the complete guide to information extraction by regular expressions with spark nlp and python
The Complete Guide to Information Extraction by Regular Expressions with Spark NLP and Python - John Snow Labs
May 15, 2026 - To install Spark NLP in Python, simply use your favorite package manager (conda, pip, etc.). For example: ... For other installation options for different environments and machines, please check the official documentation. Then, simply import the library and start a Spark session: import sparknlp # Start Spark Session spark = sparknlp.start() Regex matching in Spark NLP refers to the process of using regular expressions (regex) to search, extract, and manipulate text data based on patterns and rules defined by the user.
🌐
Towards AI
pub.towardsai.net › demystifying-information-extraction-using-llm-f1a551f01f66
Demystifying Information Extraction using LLM | by Aditya Mohan | Towards AI
January 8, 2024 - In this article, I will talk about what a very basic information extraction pipeline might look like and how, using modern Python frameworks like LangChain and Streamlit, one can easily build web applications around LLMs.
🌐
GitHub
github.com › philipperemy › stanford-openie-python
GitHub - philipperemy/stanford-openie-python: Stanford Open Information Extraction made simple! · GitHub
Stanford Open Information Extraction made simple! Contribute to philipperemy/stanford-openie-python development by creating an account on GitHub.
Starred by 684 users
Forked by 104 users
Languages   Python
🌐
Nature
nature.com › nature communications › articles › article
Structured information extraction from scientific text with large language models | Nature Communications
February 15, 2024 - The models using the Doping-English schema output English sentences with a particular structure (e.g., “the host ’<host entity>’ was doped with ’<dopant entity>’.") and the DopingExtra-English models likewise output English sentences but also includes some additional information (e.g., if one of the hosts is a solid solution and/or the concentration of a particular dopant). For the Doping-JSON schema, we used a JSON object schema with keys “hosts", “dopants", and “hosts2dopants" (which in turn has a key-value object as its corresponding value). For readers familiar with the Python programming language, these are identical to python dictionary objects with strings as keys and strings or other dictionaries as values.
🌐
Reddit
reddit.com › r/python › extracting information (text, tables, layouts) from pdfs using ocr.
r/Python on Reddit: Extracting information (Text, Tables, Layouts) from PDFs using OCR.
February 21, 2024 -

I've received an assignment whereby I am required to extract texts, tables, layouts, headers, titles, etc from PDFs (Multi-page).

These PDFs have actual text on them and not images.

So far I've tried using Camelot, PyMuPDF, and Nougat. Unfortunately, none of these modules are able to meet my client's expectations.

Due to this, I've tried AWS Textract. I've showed a sample result of Textract and they immediately loved it. However, only then they mentioned that the PDFs have sensitive data and cannot be exposed via the internet.

Now, they are looking to find an on-prem solution to get similar results as AWS Textract.

Anyone know any kind of software/tool/python module that can be self-hosted and able to get similar results as AWS Textract?

Thanks in advance.