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

  • Home
  • SEARCH
  • 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 8509553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:27:56+00:00 2026-06-11T03:27:56+00:00

I have a need to manipulate a file from within Octave in the middle

  • 0

I have a need to manipulate a file from within Octave in the middle of a routine. At the moment I end this routine by saving a file from Octave with

save data_for_training -ascii train_data

and then manually, and tediously, edit the saved file and then resume operations in a new and different Octave routine by first reading the edited file. Conceptually the file manipulations required are the reverse of those outlined in this SO posting, namely a saved file that looks like this

a b c d e f ... z 0 0 0 0 1  
g h i j k l ... z 0 0 0 1 0

has to be manipulated to

a b c d e f ... z  
0 0 0 0 1  
g h i j k l ... z  
0 0 0 1 0

where the letters are actually numbers, but I have used letters for clarity. The line breaks will always be before the fifth to last number on each line i.e. the last 0 0 0 0 1 on each line will need to be moved below the line and all numbers on all lines are space separated.

I have tagged this question with the Perl and Python tags as there are Perl and Python functions in Octave and so I assume that I can easily achieve what I want by writing a scriptfile to do the above manipulations. If I am correct in this assumption can anyone give me a start/weblink for the Perl/Python scriptfiles – I have never used either before?

  • 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-11T03:27:57+00:00Added an answer on June 11, 2026 at 3:27 am
    #!/usr/bin/env perl
    while (<>) {
       my @f = split;
       print("@f[0..$#f-5]\n@f[-5..-1]\n");
    }
    

    or

    #!/usr/bin/env perl
    while (<>) {
       s/\S\K\s+(?=\S+(?:\s+\S+){4}$)/\n/;
       print;
    }
    

    Usage:

    perl script.pl file.in >file.out
    

    or

    script.pl file.in >file.out   # Requires: chmod u+x script.pl
    

    or

    perl -pale'$_="@F[0..$#F-5]\n@F[-5..-1]"' file.in >file.out
    

    or

    perl -pe's/\S\K\s+(?=\S+(?:\s+\S+){4}$)/\n/' file.in >file.out
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF app in which I need to programatically manipulate at runtime.
I have need to return multiple results from a subquery and have been unable
I have need to pack four signed bytes into 32-bit integral type. this is
I have a need to verify the integrity of a settings file. The file
I have a need to build the data string dynamically. This is not working,
I have a plain text file that I need to read in using C#,
I need help with my jcrop preview. I am following this tutorial from railscasts
Alright, so I have a text file with some data in it, in this
I have to send some text-information from the webserver to the users. Unfortunately, this
I have a program that takes data from an excel file and manipulates it

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.