gpt4 book ai didi

linux - 如何将事件打印到文件

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:03:46 24 4
gpt4 key购买 nike

这里我试图将第一个和第二个 wt^ 及其相应的 s^ 打印到输出文件,其余的 wt^ 和 p^ 应该打印到另一个输出文件。我该怎么做?

输入文件是这样的

 wt^RHEL System Overview(contd..) 
s^Supported architectures include:
s^32-bit x86 compatible systems
s^64-bit AMD64 (Opteron) and Intel EM64T systems


wt^RHEL System Overview(contd..)
s^Common deployments
s^High volume deployments include:
s^Corporate applications (CRM, ERP, etc.)
s^Databases

wt^RHEL System Overview(contd..)
s^Network infrastructure systems
s^Web serving
s^File/print serving
s^HPC compute systems

输出文件应该是这样的

输出1.txt:

wt^RHEL System Overview(contd..) 
s^Supported architectures include:
s^32-bit x86 compatible systems
s^64-bit AMD64 (Opteron) and Intel EM64T systems


wt^RHEL System Overview(contd..)
s^Common deployments
s^High volume deployments include:
s^Corporate applications (CRM, ERP, etc.)
s^Databases

输出2.txt:

wt^RHEL System Overview(contd..)
s^Network infrastructure systems
s^Web serving
s^File/print serving
s^HPC compute systems

我试过了

count=$(cat $( ls unit-*-slides.txt | sort -n ) | grep -E "[ ]*(st\^|p\^)" >> output.txt)

但这是打印整个东西。

最佳答案

多年来我开始相信awk几乎可以做任何事情,(^ 是必需的吗?)

awk 'BEGIN {fout="file1";} /wt/{i++}i==3{fout="file2";} {print $0 > fout}' <filename>

关于linux - 如何将事件打印到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16411258/

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