Skip to main content

replacing first two lines of the variable which stores content of a file

Author: lalitpct@gmail.com (lalitpct)

hi

In a variable we are storing value of the entire file , i would like to replace the first two line , i tried with $replace but could not figure out how it can be used ,

Is there any simple way to do that ?

Regarsd

replacing first two lines of the variable which stores content of a file

Author: lalitpct@gmail.com (lalitpct)

hi

In a variable we are storing value of the entire file , i would like to replace the first two line , i tried with $replace but could not figure out how it can be used ,

Is there any simple way to do that ?

Regarsd

cutting a varible in two parts ??? sorry how do we cut it as we are not aware of pattern , we are just thinking in terms of lines


Author: lalitpct (lalitpct@gmail.com)

replacing first two lines of the variable which stores content of a file

Author: lalitpct@gmail.com (lalitpct)

hi

In a variable we are storing value of the entire file , i would like to replace the first two line , i tried with $replace but could not figure out how it can be used ,

Is there any simple way to do that ?

Regarsd

Try to find the EOL "%%^" and cut and replace the first two lines or make a list and replace.

If Aux it´s your variable.

scan Aux, "%%^"
end_of_fisrtline=$result

first_line=Aux[1:end_of_fisrtline]

scan Aux[end_of_fisrtline+1], "%%^"
end_of_secondline=$result

second_line=AUX[end_of_firstline+1:end_of_secondline]


and replace all that you need

or

Aux_list=$replace(Aux,1,"%%^","·;",2)

This make a list with 3 elements, the first line, the second line and the rest.

It should be work.

Regards.
Rafa.


Author: uniface8 (spanish_uniface@hotmail.es)

replacing first two lines of the variable which stores content of a file

Author: lalitpct@gmail.com (lalitpct)

hi

In a variable we are storing value of the entire file , i would like to replace the first two line , i tried with $replace but could not figure out how it can be used ,

Is there any simple way to do that ?

Regarsd

... an addition to Rafas version with the list:

this works only when the lines in question do not have a list seperator already.

to keep existing lists, you have to "mask" the list separator at first:

Aux_list=$replace(Aux,1,"·;","·!·;",-1)

replacing any GOLD; with GOLD!GOLD; 

Still may go wrong when there is a CRNL in the middle of a list

 

The safe thing is checking for "%%^" and warp that neatly into a little procedure you can call.

 

Uli


Author: ulrich-merkel (ulrichmerkel@web.de)

replacing first two lines of the variable which stores content of a file

Author: lalitpct@gmail.com (lalitpct)

hi

In a variable we are storing value of the entire file , i would like to replace the first two line , i tried with $replace but could not figure out how it can be used ,

Is there any simple way to do that ?

Regarsd

thanks a lot , it worked :)


Author: lalitpct (lalitpct@gmail.com)

replacing first two lines of the variable which stores content of a file

Author: lalitpct@gmail.com (lalitpct)

hi

In a variable we are storing value of the entire file , i would like to replace the first two line , i tried with $replace but could not figure out how it can be used ,

Is there any simple way to do that ?

Regarsd

cut your variable in 2 strings the first one with the 2 lines.

apply $replace to the first part

and $concat the 2 parts again.


Author: ulrich-merkel (ulrichmerkel@web.de)