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 8020589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:43:56+00:00 2026-06-04T21:43:56+00:00

I have a fairly large (1000 pages) list of structured text which I would

  • 0

I have a fairly large (1000 pages) list of structured text which I would like to convert into a data frame (preferably using R, but I am open to suggestions).

The text file looks as follows:

AC-Acrelândia
TV    Canal 18    AINDA NÃO OUTORGADO
RTV  Canal 9    RADIO TV DO AMAZONAS LTDA
RTV  Canal 10    RADIO TV DO AMAZONAS LTDA(REDENCAO)
TVD  Canal 15    RADIO TV DO AMAZONAS LTDA
TVD  Canal 15    AINDA NÃO OUTORGADO(REDENÇÃO)
FM   88,5 MHz   RADIO E TV MAIRA LTDA

AC-Assis Brasil
TV    Canal 34    AINDA NÃO OUTORGADO
RTV  Canal 6    AMAZONIA CABO LTDA
RTV  Canal 10    RADIO TV DO AMAZONAS LTDA
RTV  Canal 13    AINDA NÃO OUTORGADO
RTV  Canal 45    FUNDACAO JOAO PAULO II

and I would like to convert it into something like this:

AC  Acrelândia    TV    Canal 18    AINDA NÃO OUTORGADO
AC  Acrelândia    RTV   Canal 9     RADIO TV DO AMAZONAS LTDA
AC  Acrelândia    RTV   Canal 10    RADIO TV DO AMAZONAS LTDA(REDENCAO)
....

It seems readLines() is a good start, but I am having a hard time with the structure.

  • 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-04T21:43:57+00:00Added an answer on June 4, 2026 at 9:43 pm

    To CSV File

    Since you are open to other languages, I suggest a solution in Python. It produces a csv file looking like this:

    "AC","Acrelândia","TV","Canal 18","AINDA NÃO OUTORGADO"
    "AC","Acrelândia","RTV","Canal 9","RADIO TV DO AMAZONAS LTDA"
    "AC","Acrelândia","RTV","Canal 10","RADIO TV DO AMAZONAS LTDA(REDENCAO)"
    "AC","Acrelândia","TVD","Canal 15","RADIO TV DO AMAZONAS LTDA"
    "AC","Acrelândia","TVD","Canal 15","AINDA NÃO OUTORGADO(REDENÇÃO)"
    "AC","Acrelândia","FM","88,5 MHz","RADIO E TV MAIRA LTDA"
    "AC","Assis Brasil","TV","Canal 34","AINDA NÃO OUTORGADO"
    "AC","Assis Brasil","RTV","Canal 6","AMAZONIA CABO LTDA"
    "AC","Assis Brasil","RTV","Canal 10","RADIO TV DO AMAZONAS LTDA"
    "AC","Assis Brasil","RTV","Canal 13","AINDA NÃO OUTORGADO"
    "AC","Assis Brasil","RTV","Canal 45","FUNDACAO JOAO PAULO II"
    

    The Code

    This makes two assumptions: (1) The first line in the file, or any line following a blank line is a station name and (2) Fields are separated by two or more spaces

    #-*- coding: utf-8 -*-
    
    import re
    import csv
    
    # CREATE DATA STRUCTURE TO SIMULATE READING A TEXT FILE
    
    data = u'''AC-Acrelândia
    TV    Canal 18    AINDA NÃO OUTORGADO
    RTV  Canal 9    RADIO TV DO AMAZONAS LTDA
    RTV  Canal 10    RADIO TV DO AMAZONAS LTDA(REDENCAO)
    TVD  Canal 15    RADIO TV DO AMAZONAS LTDA
    TVD  Canal 15    AINDA NÃO OUTORGADO(REDENÇÃO)
    FM   88,5 MHz   RADIO E TV MAIRA LTDA
    
    AC-Assis Brasil
    TV    Canal 34    AINDA NÃO OUTORGADO
    RTV  Canal 6    AMAZONIA CABO LTDA
    RTV  Canal 10    RADIO TV DO AMAZONAS LTDA
    RTV  Canal 13    AINDA NÃO OUTORGADO
    RTV  Canal 45    FUNDACAO JOAO PAULO II'''.split('\n')
    
    def read_records():
        for line in data:
            yield line
    
    
    # INITIALIZE SPLITTER, READ RECORDS AND WRITE TO CSV FILE
    
    splitter = re.compile('\s{2,}')
    change_station = True
    station = ''
    
    f = open('./output.csv', 'w')
    writer = csv.writer(f, quoting=csv.QUOTE_ALL)
    
    for rec in read_records():
        rec = rec.strip()
        if rec == '':
            change_station = True
        elif change_station == True:
            station = rec.replace('-', '  ')
            change_station = False
        else:
            record = station + '  ' + rec
            record = record.encode('utf-8')
            record = re.split(splitter, record)
            writer.writerow(record)
    
    f.close()
    
    # READ IN FILE AND PRINT TO CONSOLE FOR DEMO PURPOSES
    
    f = open('./output.csv', 'r')
    print ''.join( f.readlines() )
    f.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly large text file that I would like to convert into
I have fairly large amount of data which I would like to partition into
I have a fairly large SQL database that I would like to begin managing
I have a fairly large mysql database and I would like to count all
I have a fairly large amount of data (~30G, split into ~100 files) I'd
I have a fairly large C++ application (on Windows, no other platforms planned), which
I have a fairly large SQL statement which has a number of inner joins
I have a fairly large InnoDB table which contains about 10 million rows (and
We have several fairly large JavaScript files embedded into a single script resources DLL.
I have a fairly large (new) project in which we have annotated many domain

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.