Menu

Rewrite a line in a file using Regina REXX

Sai Polury
2009-08-01
2013-05-14
  • Sai Polury

    Sai Polury - 2009-08-01

    I am using Regina REXX on AIX environment.  I have a file with 5 lines and I want to read the 3rd line and replace with new data.

    OPTIONS NOLINEOUTTRUNC
    Lineinfo = LINEIN(finename, 3)
    Lineinfo = OVERLAY(‘linedata’, Lineinfo)
    X = LINEOUT(filename, lineinfo, 3)

    If the 3rd line consists of less number of characters than the overlaid data then a new line is being added. If the overlaid data is having more number of characters than the 3rd line then the remaining characters are overwritten to the next line.

    Suppose in the third line has “Third line”, and when the above program is executed then the 3rd line is divided to ‘linedata’ and new line ‘ne’ was inserted.
    Original File:
    First Line
    Second Line
    Third Line
    Fourth Line
    Fifth Line

    After Execution:
    First Line
    Second Line
    linedata
    ne
    Fourth Line
    Fifth Line

    If the 3rd line is overlaid with ‘Refreshed-data’ then ‘data’ was overwritten on 4th line.
    First Line
    Second Line
    Refreshed-
    datath Line
    Fifth Line

    Could somebody suggest me how to overcome this?

     
  • George

    George - 2009-12-03

    OPTIONS NOLINEOUTTRUNC

    Lineinfo = LINEIN(finename, 3)

    **X = CLOSE(filename)**

    Lineinfo = OVERLAY(‘linedata’, Lineinfo)

    X = LINEOUT(filename, lineinfo, 3)

     

Log in to post a comment.