如何将多个 sed 输出行 (-e) 连接到一行



我正在使用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中有多个字符)

相关内容

  • 没有找到相关文章

最新更新