用于更改序列化 PHP 数据的 Bash 脚本
我有许多包含 php 序列化数据的文件,其中我必须用另一个字符串替换一些字符串。 Linux主机没有安装任何php。问题是将修改后的字符串调整为正确的大小。
我尝试了类似将 /share 路径替换为 /opt:
sed -re 's~s:([0-9]+):"/share([^"]*)~s:int(\1-2):/opt\2~g' file
但结果文件很糟糕:长度是垃圾表达式 int(size - 2)
知道吗?
I have many files containing php serialized data in which I have to replace some strings by another one. The linux host doesn't have any php installed. The problem is to adjust the modified string to correct size.
I tried something like to replace /share path to /opt:
sed -re 's~s:([0-9]+):"/share([^"]*)~s:int(\1-2):/opt\2~g' file
but the result file is bad: lengths are litteral expression int(size - 2)
Any idea ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个解决方案并不理想,但您可以使用 perl:
希望我已经正确理解了您的要求。这是一个示例:
编辑:这是一个修改后的脚本,用于通过变量搜索和替换就地编辑文件字符串。
This solution isn't ideal, but you could use perl:
Hopefully I've understood your requirements correctly. Here's an example:
EDIT: Here's a modified script to edit the file in-place with variable search and replace strings.