我如何猛砸一个文本文件中的每两行对? [英] How do I pair every two lines of a text file with Bash?

查看:95
本文介绍了我如何猛砸一个文本文件中的每两行对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过一个简单的bash脚本我生成多行这样的文本文件:

192.168.1.1
主机名1
192.168.1.2
主机名2
192.168.1.3
hostname3

现在我要重新格式化这个文件,所以它看起来是这样的:

192.168.1.1主机名1
192.168.1.2主机名2
192.168.1.3 hostname3

我将如何重新格式化这种方式?也许 SED


解决方案

  $ SED'$!N; S / \\ n / /'的infile
192.168.1.1主机名1
192.168.1.2主机名2
192.168.1.3 hostname3

With a simple bash script I generate a text file with many lines like this:

192.168.1.1
hostname1
192.168.1.2
hostname2
192.168.1.3
hostname3

Now I want to reformat this file so it looks like this:

192.168.1.1 hostname1
192.168.1.2 hostname2
192.168.1.3 hostname3

How would I reformat it this way? Perhaps sed?

解决方案

$ sed '$!N;s/\n/ /' infile
192.168.1.1 hostname1
192.168.1.2 hostname2
192.168.1.3 hostname3

这篇关于我如何猛砸一个文本文件中的每两行对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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