合并两行成一个 [英] Merge two lines into one

查看:279
本文介绍了合并两行成一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的文本文件。第一行是关键点,第二行是VALUE。

I have a text file with the following format. The first line is the "KEY" and the second line is the "VALUE".

KEY 4048:1736 string
3
KEY 0:1772 string
1
KEY 4192:1349 string
1
KEY 7329:2407 string
2
KEY 0:1774 string
1

我需要的关键的在同一行中的值。所以输出应该是这样的......

I need the value in the same line as of the key. So the output should look like this...

KEY 4048:1736 string 3
KEY 0:1772 string 1
KEY 4192:1349 string 1
KEY 7329:2407 string 2
KEY 0:1774 string 1

这将是更好的,如果我可以使用一些分隔符如$或者,
KEY 4048:1736串,3

It will be better if I could use some delimiter like $ or , KEY 4048:1736 string , 3

我如何合并两行吗?

推荐答案

awk的:

awk 'NR%2{printf "%s ",$0;next;}1' yourFile

请注意,有一个在输出的最后一个空行。

note, there is an empty line at the end of output.

sed的:

sed 'N;s/\n/ /' yourFile

这篇关于合并两行成一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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