gpt4 book ai didi

sed - 处理交替行bash

转载 作者:行者123 更新时间:2023-12-04 21:01:12 25 4
gpt4 key购买 nike

我有一个这样的文件

line1
this is line1
line2
this is line2
line3
this is line3

我想使用 awk 或 sed 来删除每个备用行的尾随换行符,以便像这样合并它们
line1: this is line1    
line2: this is line2
line3: this is line3

我如何使用 awk 或 sed

最佳答案

$ cat input 
line1
this is line1
line2
this is line2
line3
this is line3
$ awk 'NR%2==1 {prev=$0} NR%2==0 {print prev ": " $0} END {if (NR%2==1) {print $0 ":"}}' input
line1: this is line1
line2: this is line2
line3: this is line3
$

关于sed - 处理交替行bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10859187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com