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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:37:55+00:00 2026-05-27T21:37:55+00:00

I am trying to retrieve particular data from a txt file and would like

  • 0

I am trying to retrieve particular data from a txt file and would like to save it in a new txt file.

Here’s the sample of the data that i would like to retrive from the text file:

//
FORMAT CDDF1.0
DOMAIN 1cuk003
VERSION   3.1.0
VERDATE   20-Jan-2007
NAME   Ruva protein. Chain: null. Engineered: yes
SOURCE Escherichia coli. Strain: 12 bl21 (de3).  Expressed in: escherichia co
SOURCE li.
CATHCODE  1.10.8.10
CLASS  Mainly Alpha
ARCH   Orthogonal Bundle
TOPOL  Helicase, Ruva Protein; domain 3 
HOMOL  DNA helicase RuvA subunit, C-terminal domain
DLENGTH   48
DSEQH  >pdb|1cuk003
DSEQS  TDDAEQEAVARLVALGYKPQEASRMVSKIARPDASSETLIREALRAAL
NSEGMENTS 1
SEGMENT   1cuk003:1:1
SRANGE START=156  STOP=203
SLENGTH   48
SSEQH  >pdb|1cuk003:1:1
SSEQS  TDDAEQEAVARLVALGYKPQEASRMVSKIARPDASSETLIREALRAAL
ENDSEG
//

From those details, I am trying to retrieve “DOMAIN, SRANGE START AND STOP”, but i would just like to select the information, not the header of the file name. For an example, DOMAIN is 1cuk003, i would just like to select “1cuk003” from it.

Do i need to store this data in an array? Or is there any other way that i could use to solve this problem. Also, i have over 10,000 entrires more of this data with different values.

The other part is that, once i have retrived those data, i would then like to format the data using “sprintf”, eg. sprintf('INSERT INTO postgres VALUES %d,%d.',array1,array2);

Is this possible?

Basically, in the end, I would like to have a text file, containing SQL INSERT statements of all the data been stored in which i can just easily execute them in PostgreSQL.

I did a test code in which it opens a text file, replicates the data and saves it in a new text file.

fid = fopen('sample.txt');    
readfile = fread(fid, '*char');    
fclose(fid);                        
output = fopen('output_sample.txt', 'wt');
fprintf(output,'%s \n', readfile);
fclose(output);

Thank you.

  • 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-05-27T21:37:56+00:00Added an answer on May 27, 2026 at 9:37 pm

    There are several MATLAB functions which come in handy:

    • fgetl: Read a single line from a file
    • strtok: Split a string
    • switch: Choose from different actions
    • regexp: Match regular expressions

    Armed with these, the basic workflow is like that:

    domain = '';
    start = '';
    stop = '';
    fin = fopen('sample.txt', 'r');
    fout = fopen('output.txt', 'w');
    % TODO: Add error check!
    while true
        line = fgetl(fin); % Get the next line from the file
        if ~ischar(line)
            % End of file
            break;
        end
        [key, value] = strtok(line); % Split line at the first space
        switch key
            case 'DOMAIN'
               % Store domain
               domain = value;
            case 'SRANGE'
               % Retrieve start and stop values
               m = regexp(value, 'START=(\d+)\s*STOP=(\d+)', 'tokens');
               start = m{1};
               stop = m{2};
    
               % Print result
               fprintf(fout, 'INSERT INTO postgres VALUES %s, %s, %s.\n', domain, start, stop);
        end
    end
    fclose(fin);
    fclose(fout);
    

    I currently do not have access to a MATLAB installation, so the code above is not tested. It should get you going, though.

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

Sidebar

Related Questions

Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I'm trying to retrieve a file from a server using SFTP (as opposed to
I'm trying to retrieve data from an SQL Server 2000 server, and place into
I'm trying to retrive some data from a web site . I wrote a
Using ClearCase, I would like to retrieve all the elements of the VOB that
I am trying to retrieve results from search bar text in Core Data on
I'm trying to retrieve an XML stream from a URL. For most URLs my
I am trying to retrieve the attribute name and type that exist in an
I'm trying to retrieve the SubItem in my ListView from another thread, but I
I am trying to retrieve the correct value from an ArrayList of objects (.NET

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.