我的文本文件输出看起来像这样,分为两行:
DelayTimeThreshold|MaxDelayPerMinute|Name
10000|5|rca
我想要的输出太像这样:
DelayTimeThreshold 10000
MaxDelayPerMinute 5
Name rca
我没有运气尝试这个:
sed '$!N;s/|/\n/' foo
欢迎任何建议,谢谢。
最佳答案
由于您只有两行,这可能是一种方法:
$ paste -d' ' <(head -1 file | sed 's/|/\n/g') <(tail -1 file | sed 's/|/\n/g')
DelayTimeThreshold 10000
MaxDelayPerMinute 5
Name rca
按件。让我们获取第一行并将每个管道 |
替换为新行:
$ head -1 file | sed 's/|/\n/g'
DelayTimeThreshold
MaxDelayPerMinute
Name
对最后一行执行相同的操作:
$ tail -1 file | sed 's/|/\n/g'
10000
5
rca
然后只需粘贴两个结果并用空格作为分隔符即可:
paste -d' ' output1 output2
关于python - 将两行中的值附加到 key 对中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19911316/