我有一些txt文件,如下所示:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAUAAtADASIAAhEBAxEB/8QAHQAAAgIDAQEBAAAAAAAAAAAAAwQCBQEGBwgACf/EAFAQAAIBAwMCBAQEBAMHAQUBEQECAwAEEQUSIQYxEyJBUQcUYXEIMoGRFSNCoVKxwQACAwEBAQAAAAAAAAAAAAABAgADBAUGB//EADkRAAICAgIBAgUBBwIFBAMAAAABAhEDIRIxBCJBBRMyUWFxFCOBkaGx0TPBJEJS4fAGFTSSQ3KC/9oADAMBAAIRAxEAPwD8+4YcMMjIBoqXkcTEAkkcDB709Bp9tpQ/Y9xScplulJXkZwAO1bD/ALm3lvAJbiI/zAMKOcfpU
我想在脚本中添加一些命令来删除:
data:image/jpeg;base64,
并获得以下效果:
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAUAAtADASIAAhEBAxEB/8QAHQAAAgIDAQEBAAAAAAAAAAAAAwQCBQEGBwgACf/EAFAQAAIBAwMCBAQEBAMHAQUBEQECAwAEEQUSIQYxEyJBUQcUYXEIMoGRFSNCoVKxwQACAwEBAQAAAAAAAAAAAAABAgADBAUGB//EADkRAAICAgIBAgUBBwIFBAMAAAABAhEDIRIxBCJBBRMyUWFxFCOBkaGx0TPBJEJS4fAGFTSSQ3KC/9oADAMBAAIRAxEAPwD8+4YcMMjIBoqXkcTEAkkcDB709Bp9tpQ/Y9xScplulJXkZwAO1bD/ALm3lvAJbiI/zAMKOcfpU
我尝试使用一些sed命令,但没有用,而且我没有更多的主意。
答案 0 :(得分:0)
您可能忘了跳过反斜杠。再试一次:
sed 's/data:image\/jpeg;base64,//' file > newFile
答案 1 :(得分:0)
如果要处理包含/
的文本输入,则可以在#
内使用@
或sed
等不同的分隔符。
sed 's#data:image/jpeg;base64,##' file
或此文件以替换文件中的内容。
sed -i 's#data:image/jpeg;base64,##' file