linux系统中如何把连续的两行数据转换成一行数据

1、测试数据

root@PC1:/home/test2# cat a.txt
1 e d
2 a g
3 w e
4 d g
5 g j
6 e j
7 l m
8 i n

 

2、awk命令实现

root@PC1:/home/test2# cat a.txt
1 e d
2 a g
3 w e
4 d g
5 g j
6 e j
7 l m
8 i n
root@PC1:/home/test2# awk '{if(NR % 2 != 0) {printf("%s ", $0)} else {print $0}}' a.txt
1 e d 2 a g
3 w e 4 d g
5 g j 6 e j
7 l m 8 i n

 

3、sed命令实现

root@PC1:/home/test2# cat a.txt
1 e d
2 a g
3 w e
4 d g
5 g j
6 e j
7 l m
8 i n
root@PC1:/home/test2# sed 'N; s/\n/ /' a.txt
1 e d 2 a g
3 w e 4 d g
5 g j 6 e j
7 l m 8 i n

 

相关文章

Centos系统之Shell编程基础知识
从Export理解Shell环境和变量生存期
linux shell数组变量、类型及规则
Centos编程Shell基本工作原理方案
Centos操作系统编程之Shell 问答录
rsync-linux备份脚本