我使用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....
答案 0 :(得分:1)
它的第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
)