Change config file on Linux host

This is driving me crazy! I am looking at a file and it is relevance if the file has a line that shows allow_host = A B C D

I need to replace this line with allow_host = A B C D E F G H

What is the method in which to accomplish this with BigFix Actionscript? Is it best just to use a Linux command one liner with sed?

1 Like

Hello bkone,
It might be something like that, though I did not test it:

// Define a filename
parameter "filename" = "{pathname of file ("/tmp/myfile.ini") whose (exists lines whose (it contains "allow_host") of it )}"

// Define old and new text
parameter "textToReplace" = "allow_host = A B C D"
parameter "newText" = "allow_host = A B C D E F G H"

// iterate through the file replacing lines as necessary
appendfile {concatenation "%0a" of ( if (it contains (parameter "textToReplace")) then ((preceding text of first (parameter "textToReplace") of it) & (parameter "newText") & (following text of first (parameter "textToReplace") of it) ) else it ) of lines of file (parameter "filename")}

// backup the old file
move "{parameter "filename"}" "{parameter "filename"}.bak"

// replace with the new file
move __appendfile "{parameter "filename"}"

Regards,
Vitaliy

1 Like

Thanks that appears to be what I was looking for!