[英]using sed or similar to modify lines in a file
我有一個巨大的文件由以下組成:
this is text
1234.1234567
this is another text
1234.1234567
等等
我想把它轉移到:
this is text:1234.1234567
this is another text:1234.1234567
這可能使用sed嗎? 或任何其他類似的命令?
謝謝
如果您只想使用:
作為分隔符來連接行,則可以使用paste
:
paste -d : - - < file.txt
或者使用awk
:
awk -v sep=: '{ if (NR % 2 == 0) { print prev sep $0 } else prev = $0 }' file.txt
如果您的行只包含字母和其他包含浮點數的行,則可以執行以下操作:
awk '/[a-zA-Z]+/ {printf "%s:", $0}
/[0-9.]+/ {print $0}' data
data
是文件名。 您可以將輸出重定向到另一個文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.