使用SED插入同一字段的两个字符之间的空间



我正在尝试在文件的每个两个字段的中间插入一个太空字符«»(例如,在我的情况00或CC中(,以使字段加倍进入两个字段,我的字段定界符是一个空间。

我正在寻找bash解决方案,但是python-3.x脚本也可以做。

REGEX可以工作吗?

Python的RE模块可以为您提供帮助。但是像

import re
#searches for a word boundary, two characters and another boundary.
#replaces it by <firstchar><space><seconchar>
#for every occurence in the contentsoffile.
re.sub(r"b(.)(.)b",r"1 2",contentsoffile)

您可以使用简单的

读取文件
with open("myfile.something","r") as f:
    contentsoffile = f.read()

最新更新