我有一个输入的日志文件,这种格式的桑达替代和外部命令
May 23 2012 11:59:56
a;b;c
May 21 2012 16:54:12
d;e;f
May 19 2012 16:22:52
g;h;i
...
我希望将它输出这种格式
2012-05-23
a;b;c
2012-05-21
d;e;f
2012-05-19
g;h;i
...
使用sed
,我知道如何替换日期行
% sed 's/.*:.*:.*/match_string/' input.txt
match_string
a;b;c
match_string
d;e;f
match_string
g;h;i
...
使用date
,我知道如何转换日期:
% date -d 'May 23 2012 11:59:56' '+%Y-%m-%d'
2012-05-23
但是如何让match_string在sed命令中被评估呢?
您可能是想在'date'命令中说'5月23日...'而不是'5月23日...」。 – devnull
我纠正了打字错误,对不起。 –
是否需要外部命令?见http://sed.sf.net/grabbag/tutorials/lookup_tables.txt – potong