1

I need to replace a complex string in several files in a directory.

The string that needs replaced is:

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++dGAbFvZAoTvEmlwZxKsoTtb7Tulq3CR9RfCI64T64qSjlUugSbz41o9DLlOQqOIAZhSEmBIrZIBorzmjVB0Oh94OhUE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IK0+Zkz3Ypym4SGAcaaOB2K3TL1AF1i+E3kTQOKb2XMbpbfLtyGZKfqtr9NlwwUxtcVGdr5ICiSbyjykZTcoEYWPgWKVLewXKsNDqmMwfENNt7dSp8qK0fr/JEMgrIpN5u728WRhFgphKXxq7WR2zTeN7qSPru2usezUkhNaMV1Wak6bimvQY3hQ9ny6XTlZGbNrwaVxjMFNgwvtcFlcfVlawGdry6wyerdYia8fJcbexvLkxibXEm9+UOx7lSUyab4ALPECYtiUXCw8HP8EM3bxDEulyspAb5sxyVOVv046sVtFHdt4khCzHb9lsfFH23WeG5WCLIlgMyYRH6p2DB1+cMLa1PQR7PpYmxaQejaQSX+JSul2tjcRy1loy3MSuftVq36OJHIy4+Kw974GBydei1UtwVloim+3y3L2VNE/ML4Z1ZfFs8iFrGIRSxi/6/9C8Ubb5YmcgHHAAAAAElFTkSuQmCC

With: ./logo.jpg

I'm having all kinds of issues using sed for the replacement due to the various special characters in the string that needs replaced.

  • For the given string, you could use sed with another delimiter: sed 's|yourstringgoeshere|./logo.jpg|'. – don_crissti Dec 7 '14 at 12:58
  • There aren't really any special characters in that string. As sed supports nearly any character as delimiter, you only need to pick something that is not contained in the string you search for or that you want to replace it with. In your case, probably | or _ should work, just tested. For more details see grymoire.com/Unix/Sed.html – doktor5000 Dec 7 '14 at 13:04
0

How about a regular expression:

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

Look for the beginning and the end of the string and replace with .\/logo.jpg in filename.

Use -i to replace the content in the filename.

  • Nope.. doesn't seem to work. – schwach Dec 23 '14 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.