How can I use a shell script to add and replace lines in a file?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
# splits into an array, -1 is the last field
$F[-1] = "XXX" if m/Timeout/;
$F[-1] = "XXX" if m/KeepAlive/;
$F[-1] = "XXX" if m/deliver_queue_load_max/;
# you get the idea?
print "@F\n" ;
perl -i.bak <script> <file>
will edit the file and create a backup .bak
The backslash character isn't needed in your case because the sed expression is contained in single quotes. Suppose the name of the file you were changing was named "http one.conf" in that case you would either need to escape the space, or put the argument in quotes. If the filename contained the "$" character, then you would need either a backslash or single quotes.
All of the whitespace characters and special characters are listed in the bashref manual.