我正在使用sed
从日志文件中提取一些数据。我的命令如下所示:
sed -n -e 's/.*(date).*/1/p' -e 's/.*(details in that entry).*/1/p'-e 's/.*(some more details).*/1/p'
这总是产生 2 行或更多行:
date
some details
some more details
date(2nd entry)
some details ( 2nd entry )
some more details (2nd entry)
等等...
如何将来自 sed
命令集的行直接连接到这样的一行?
date some details some more details
date some details some more details....
它
每 3 行:
awk 'ORS=NR%3?" ":RS' file
date some details some more details
date some details some more details
或
paste -d " " - - - < file
date some details some more details
date some details some more details
如果可以使用date
作为触发词,则可以使用此gnu awk
awk 'NR>1 {$1=RS FS $1;print}' RS="date" file
date some details some more details
date some details some more details
(gnu awk
由于RS
中有多个字符)