[英]replace string in a file using sed
I have file with data fields in this format YYYY-MM-DD HH:MM:SS but I noticed the export set the Months values to be the same as the minutes value. 我有带有格式为YYYY-MM-DD HH:MM:SS的数据字段的文件,但我注意到导出将Months值设置为与分钟值相同。 I want to use sed to replace the Month value for all line to the same value.
我想使用sed将所有行的Month值替换为相同的值。
I am trying this and it didn't work: 我正在尝试这样做,但没有成功:
sed "s/-[0-9]{2,}-/-08-/g" test.txt
Anyone have an idea how to do this? 有人知道如何执行此操作吗?
$ sed 's/^\(....\)-../\1-09/' < input
Input: 输入:
$ cat input
2012-52-05 09:52:00
2012-53-05 09:53:00
2012-54-05 09:54:00
Output: 输出:
$ sed 's/^\(....\)-../\1-09/' < input
2012-09-05 09:52:00
2012-09-05 09:53:00
2012-09-05 09:54:00
使用GNU sed:
sed -r 's/([0-9]{4})-[0-9]{2}-/\1-08-/' infile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.