how can I combine these lines

2019-03-01 16:29发布

How can I combine these lines (NOTE: this is just an excerpt from a much larger file):

interface GigabitEthernet0/0
 no ip proxy-arp
interface GigabitEthernet0/0.202
 no ip proxy-arp
interface GigabitEthernet0/0.358
 no ip proxy-arp
interface FastEthernet0/0/1.26
 no ip proxy-arp
interface GigabitEthernet0/0
 no ip proxy-arp
interface GigabitEthernet0/0.202
 no ip proxy-arp
interface GigabitEthernet0/0.358
 no ip proxy-arp
interface FastEthernet0/0/1.26
 no ip proxy-arp
interface Loopback0
 no ip proxy-arp
interface Loopback1
 no ip proxy-arp
interface Loopback26
 no ip proxy-arp
interface GigabitEthernet0/0/0
 no ip proxy-arp

so that they resemble this:

interface GigabitEthernet0/0 | no ip proxy-arp
interface GigabitEthernet0/0.202 | no ip proxy-arp
interface GigabitEthernet0/0.358 | no ip proxy-arp
interface FastEthernet0/0/1.26 | no ip proxy-arp
interface GigabitEthernet0/0 | no ip proxy-arp
interface GigabitEthernet0/0.202 | no ip proxy-arp
interface GigabitEthernet0/0.358 | no ip proxy-arp
interface FastEthernet0/0/1.26 | no ip proxy-arp
interface Loopback0 | no ip proxy-arp
interface Loopback1 | no ip proxy-arp
interface Loopback26 | no ip proxy-arp
interface GigabitEthernet0/0/0 | no ip proxy-arp

I've tried a few different solutions that I have found online, but none of them seem to work correctly for my situation

4条回答
闹够了就滚
2楼-- · 2019-03-01 17:06
while IFS= read line1 && IFS= read line2; do
    printf "%s | %s\n" "$line1" "$line2"
done < file.txt
查看更多
一纸荒年 Trace。
3楼-- · 2019-03-01 17:07

paste can do it:

paste -d '|' - - < file
查看更多
不美不萌又怎样
4楼-- · 2019-03-01 17:09

Try this sed one-liner:

sed 'N;s/\n/ | /;s/\r//g' file.txt
查看更多
老娘就宠你
5楼-- · 2019-03-01 17:14
 awk '{printf "%s%s",$0,(NR%2?"|":"\n")}' file
查看更多
登录 后发表回答