Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
modifying a text file by inserteting lines in specific positions

Subject: modifying a text file by inserteting lines in specific positions

From: Ondrej

Date: 15 Jan, 2010 00:49:05

Message: 1 of 2

Hi Guys, is there a way of inserting specific lines into a text file using Matlab,… it is not that complicated what I need to do but I somehow found it difficult with matlab or my skills are limited,... lets say I have a text file like this:

** STEP: add_pass2
**
*Step, name=add_pass2
add_pass2
*Heat Transfer, end=PERIOD, deltmx=400.
1e-10, 1e-10, 1e-15, 1e-10,
**
** STEP: add_pass3
**
*Step, name=add_pass3
add_pass3
*Heat Transfer, end=PERIOD, deltmx=400.
1e-10, 1e-10, 1e-15, 1e-10,

etc..

and I need to search for a pattern “STEP: add_pass” and then insert two specific lines in the 4th line after “STEP: add_pass” so the file should look like this:


** STEP: add_pass2
**
*Step, name=add_pass2
add_pass2
*Heat Transfer, end=PERIOD, deltmx=400.
1e-10, 1e-10, 1e-15, 1e-10,
line 1 (inserted) #######
line 2 (inserted) #######
**
** STEP: add_pass3
**
*Step, name=add_pass3
add_pass3
*Heat Transfer, end=PERIOD, deltmx=400.
1e-10, 1e-10, 1e-15, 1e-10,
line 1 (inserted) #########
line 2 (inserted) #########

etc..

can someone help, please?
many thanks, ondrej

Subject: modifying a text file by inserteting lines in specific positions

From: TideMan

Date: 15 Jan, 2010 02:16:18

Message: 2 of 2

On Jan 15, 1:49 pm, "Ondrej " <ondrej.muran...@ansto.gov.au> wrote:
> Hi Guys, is there a way of inserting specific lines into a text file using Matlab,… it is not that complicated what I need to do but I somehow found it difficult with matlab or my skills are limited,... lets say I have a text file like this:
>
> ** STEP: add_pass2
> **
> *Step, name=add_pass2
> add_pass2
> *Heat Transfer, end=PERIOD, deltmx=400.
> 1e-10, 1e-10, 1e-15, 1e-10,  
> **
> ** STEP: add_pass3
> **
> *Step, name=add_pass3
> add_pass3
> *Heat Transfer, end=PERIOD, deltmx=400.
> 1e-10, 1e-10, 1e-15, 1e-10,  
>
> etc..
>
> and I need to search for a pattern “STEP: add_pass” and then insert two specific lines in the 4th line after “STEP: add_pass” so the file should look like this:
>
> ** STEP: add_pass2
> **
> *Step, name=add_pass2
> add_pass2
> *Heat Transfer, end=PERIOD, deltmx=400.
> 1e-10, 1e-10, 1e-15, 1e-10,  
> line 1 (inserted) #######
> line 2 (inserted) #######
> **
> ** STEP: add_pass3
> **
> *Step, name=add_pass3
> add_pass3
> *Heat Transfer, end=PERIOD, deltmx=400.
> 1e-10, 1e-10, 1e-15, 1e-10,  
> line 1 (inserted) #########
> line 2 (inserted) #########
>
> etc..
>
> can someone help, please?
> many thanks, ondrej

This is a job for Perl, not Matlab.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us