skip to Main Content

I need to extract paragraphs from a .txt file where each paragraph starts with letter Abstract as shown below.

Abstract: Massive multiple-input multiple-output antenna systems, millimeter wave communications, and ultra-dense networks have been widely perceived as the
three key enablers that facilitate the development and deployment of 5G
systems. We present a flexible, rapidly deployable, and cross-layer artificial
intelligence (AI)-based framework to enable the imminent and future demands on
5G and beyond infrastructure. We present example AI-enabled 5G use cases that
accommodate important 5G-specific capabilities and discuss the value of AI for
enabling beyond 5G network evolution.


Abstract: The wireless revolution has already started with the specified vision, overall objectives, and the first official 3GPP release of 5th generation (5G) wireless networks. Despite the development of several modern communication technologies, since the beginning of the modern era of digital communications, we have been mostly conveying information by altering the amplitude, the phase, or the frequency of sinusoidal carrier signals, which has inherent drawbacks.On the other hand, index modulation (IM) provides an alternative dimension to transmit digital information: the indices of the corresponding communication systems’ building blocks.


Abstract: Security is a primary concern for the networks aiming at the utilization of Cellular (C) services for connecting Vehicles to Everything (V2X). At present, C-V2X is observing a paradigm shift from Long Term Evolution (LTE) – Evolved Universal Terrestrial Radio Access Network (E-UTRAN) to Fifth Generation (5G) based functional architecture. However, security and credential management are still concerns to be resolved under 5G-V2X.


How can i achieve this with a python script?

2

Answers


  1. I assume each paragraph is separated by new lines. If so, you can just use splitlines():

    with open("file", "r") as fd:
        lines = fd.read().splitlines()
    

    If needed, you can remove “Abstract: ” like so:

    lines2 = [i[len("Abstract: ")] for i in lines]
    
    Login or Signup to reply.
  2. Like so:

    with open("./abstract.txt", "r") as f:
        for line in f:
            print(line)
    

    What is happening here?

    We are creating a context manager (with) which manages the file handler. This prevents leaving the file open when we are done, and other headaches. We assign that to f with as f. The “mode” is plain reading with the argument to open as "r".

    After that, our f is a “file-like” like object that is iterable, and so we can do list operations like for loops and list comprehensions with it. Each line is a string and we can do string operations on it like you see in @bunbun’s excellent answer.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search