如何合并数目不详的两个模式之间的多条线路到一个使用一行AWK [英] How to merge unknown number of multiple lines between two patterns into a single line using awk

查看:118
本文介绍了如何合并数目不详的两个模式之间的多条线路到一个使用一行AWK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文本文件,每个文件都会有一些信息,如下

I have some text files where each file will have some information as below

235.91 245.67 B: some information here
246.79 246.99 A: some other information here,
more information here,
and may be here
247.45 248.99 A: some other text here,
some more here
249.98 ---- 

和图案重复

我要安排文如下:

235.91 245.67 B: some information here
246.79 246.99 A: some other information here, more information here, and may be here
247.45 248.99 A: some other text here. some more here
249.98 -----

这意味着我要合并所有两个匹配模式之间的线(与它们之间的空格)

That means I want to merge all the lines between two matching patterns( with spaces between them)

我想每一行开始与编号为图案。数字始终具有小数点后两位数字小数点。一图案和下一个图案之间的行数而变化(可以有在所有的一个或多个线或无线)。

I want every line to start with the numbers as the pattern. The numbers always has a decimal point with two digits after the decimal point. The number of lines between a pattern and the next pattern varies (There can be one or more lines or no lines at all).

能有人帮我pferably做到这一点使用shell脚本$ P $用awk?

Could some one help me do this using shell scripting preferably using awk?

推荐答案

这听起来像你需要的东西是这样的:

It sounds like you need something like this:

awk '
{ printf "%s%s", ($1 ~ /\.[[:digit:]][[:digit:]]/ ? rs : FS), $0; rs=RS }
END { print "" }
' file

这篇关于如何合并数目不详的两个模式之间的多条线路到一个使用一行AWK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆