By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,589 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,589 IT Pros & Developers. It's quick & easy.

search line by line and modify file

P: 2
file contain below text

server = abc
tapeserver = 123
filer = 456

server = def
tapeserver = 123
filer = 456

server = ghk
tapeserver = 123
filer = 456

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

server = xyz
tapeserver = 666
filer = 999
3 Weeks Ago #1
Share this Question
Share on Google+
3 Replies

P: 92
- 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.
3 Weeks Ago #2

Expert 100+
P: 618
It is simple to find lines that start with "server". What problems are you having with your code to do this?
3 Weeks Ago #3

P: 2
Hello, good day

i Need to change server,tapeserver,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 ..
3 Weeks Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.