替换多个包含特殊字符的文件中的复杂文本字符串

替换多个包含特殊字符的文件中的复杂文本字符串

我需要替换目录中多个文件中的复杂字符串。

需要替换的字符串是:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQoAAAAkCAAAAABUcSvnAAAHbklEQVRo3u2Ya0xURxTHR9Yt6CJdLSU0hFoxPhIS41ujDex+MATdaLElpS3EVCtpaqNVjEYqgoY0SI2iranBR03aoHW7TROrtkq6rWJFm6rhYdUgGjE2xLdZWUTgds45c+c+9oFYsF/2JMw9e+ec/5z5cR8zl7GIRSxiEYtY39pg58LCwsJlGYNNfm9t0nuYGh8u5j/I951Nb0ary4mGX/QD3ZkNtx76/f5HdxqmGPwjFFMxAoLS0a+UQh6Px8WzPdLY2JOtDzC1ZT7bxyNOejxlkLqvWdg+xmbUqfLTWGyFKOjDqFyev55RC+F1Hk9FCk+1OIR4jmW6qtKszShlL/UW2VjU7DpRbRyTkc1HKnISooKgcCjCFsMvch3getUOpdjgq16jjQcVo3vOLCTDFfa1dL1SpnGoTt7L2E8ypop9rrq+UcXYW2xIvTKSj+RTYxwObSDVhl5RT5Wy12Tkdl1NIJMeDsUZ/mMUuR+oKNrOt0kUt4Uv5WZIFO0GoSsGFChzuc0wH2WBEYU2FMVcPnSbtx8FQ6EUqYPiPyYIihk69th9qAZ9AwqcbVAUP/O/xwPkdNarKGpH1EoUW4UPAd3QrOJBVZSQpAphh4X5fH5w/D4fyYyqlfPBiA0kf/8Et636oShmU+JJGMqMAlMPE4o/J+yQKM6DjHFCExZrKBKzJIpljZAKmUdDocCrIZmxOTSzgyoKKqHY0EJAzQPe7NLuojmq0DH1/nKojiZDbU2rdiV4RQ3mmBIayozi+jW4Ypg4s7SpqWmpHMY0ITaN91YJ3yFROHAMyD8WCgW7S4oFNLOLWn15RUVFaQIC+RBQ8r2YyDlKKFCFXoHmnUAUkJpH0/yKBghEoYsJjsJbSHcCnRmelpY2PCQKO++dGAbFvZAoTvEmlwZxKsoTtb7Tulq3CR9Rf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5w1csMSSuCPDTkVgd+B/zpro3z4r2BTTLzMy5/PAWOyBHWaPzV+pRrIK0+Zkz3Ypym4SGAcaaOB2K3TL1AF1i+E3kTQOKb2XMbpbfLtyGZKfqtr9NlwwUxtcVGdr5ICiSbyjykZTcoEYWPgWKVLewXKsNDqmMwfENNt7dSp8qK0fr/JEMgrIpN5u728WRhFgphKXxq7WR2zTeN7qSPru2usezUkhNaMV1Wak6bimvQY3hQ9ny6XTlZGbNrwaVxjMFNgwvtcFlcfVlawGdry6wyerdYia8fJcbexvLkxibXEm9+UOx7lSUyab4ALPECYtiUXCw8HP8EM3bxDEulyspAb5sxyVOVv046sVtFHdt4khCzHb9lsfFH23WeG5WCLIlgMyYRH6p2DB1+cMLa1PQR7PpYmxaQejaQSX+JSul2tjcRy1loy3MSuftVq36OJHIy4+Kw974GBydei1UtwVloim+3y3L2VNE/ML4Z1ZfFs8iFrGIRSxi/6/9C8Ubb5YmcgHHAAAAAElFTkSuQmCC

和:./logo.jpg

由于字符串中需要替换的各种特殊字符,我在使用 sed 进行替换时遇到了各种问题。

答案1

正则表达式怎么样:

sed -r -i 's/(data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQoAAAAkCAAAAABUcSvnAAAHbklEQVRo3u2Ya0xURxTHR9Yt6CJdLSU0hFoxPhIS41ujDex).*(HHAAAAAElFTkSuQmCC)/.\/logo.jpg/g' filename

查找字符串的开头和结尾并替换为.\/logo.jpgin filename

用于-i替换文件名中的内容。

相关内容