search line by line and modify file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krajeevk10
    New Member
    • Jul 2019
    • 2

    search line by line and modify file

    file contain below text

    [a]
    server = abc
    tapeserver = 123
    filer = 456


    [b]
    server = def
    tapeserver = 123
    filer = 456

    [c]
    server = ghk
    tapeserver = 123
    filer = 456


    i want to modify only lines related to [a] , i am looking [a] output like below ..

    [a]
    server = xyz
    tapeserver = 666
    filer = 999
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 655

    #2
    - There is no way of insertion into the middle of the file than re-writing it. The changes can be saved to a temporary file and later, it can be renamed.

    - Write the first four changed lines to a temporary file. Then start reading from the original file and skip any operation for these lines. The later part of the file can be copied to the temporary file. And then rename the temporary file.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      It is simple to find lines that start with "server". What problems are you having with your code to do this?

      Comment

      • krajeevk10
        New Member
        • Jul 2019
        • 2

        #4
        Hello, good day

        i Need to change server,tapeserv er,filer for only Set [a] , remaining sets no need to modify, also set [a] line not starting from zero'0', it is some where in file ,so am facing some difficult to apply logic how to search from set [a] only ,also followed 3 lines need to modify ..

        Comment

        Working...