sed 替换固定长文件中的字段

通过sed替换固定长文件中某个位置开始的字符串

比如要把从第100个字节开始的8个字符替换成今天的日期,代码应该如下

#!/bin/sh

in_file=./xxx.in
out_file=./xxx.out

today=20150101

sed -e "s/\(^.\{99\}\)[0-9]\{8\}\(.*\)/\1${today}\2/" ${in_file} > ${out_file}

猜你喜欢

转载自jak47.iteye.com/blog/2170336