Find and replace a line of text within a file with thirst

0
I have a problem with the regular expression, I have a file in ppd format that contains configurations of a printer installed in my sector, I need to change one line from one file to another with the command sed , the problem is greater and that this line that I try to change inside the file has special characters of a command, so I have to replace the whole line with another one inside the file, here is the expression I tried:

Excerpt from file where a line needs to be changed:

*DefaultLockedPrintPassword: None

*LockedPrintPassword None/None: ""

*LockedPrintPassword 4001/4001: "%% FoomaticRIPOptionSetting: 

LockedPrintPassword=4001"

*FoomaticRIPOptionSetting LockedPrintPassword=4001: "mark\n&&

(&user;) (20'date +%y%m%d%R | sed 's/://'') (4001) {secureprint} stopped\n&&

cleartomark\n"
*End

I need to change this line:

(&user;) (20'date +%y%m%d%R | sed 's/://'') (4001) {secureprint} stopped\n&&

For this:

(&userid;) (20'date +%y%m%d%R | sed 's/://'') (9999) {secureprint} started\n&&

I would have to do this on several computers, the worst that I add the sed command to change this line it confuses because it treats the line that I want to change with another command because it is a command that the printer file executes, that file and a Linux printer configuration file.

    
asked by anonymous 16.01.2018 / 17:35

1 answer

0

Escaping special characters, such as bars, chase, & etc.

The following sed command replaces lines that begin with (& user;) and insert the new line given:

sed -i "s/^(&user;).*/(\&userid;) (20\'date +%y%m%d%R | sed 's\/:\/\/'\') (9999) {secureprint} started\\n\&\&/" /pasta/nome_do_arquivo

Obs. : You must enter the path for the file to be changed.

    
16.01.2018 / 19:38