这里我试图打印第一个和第二个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
输出文件应该是这样的
output1.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
output2.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)
但这是印刷整个东西。
答案 0 :(得分:1)
多年来我开始相信awk
几乎可以做任何事情,(^
是必要的吗?)
awk 'BEGIN {fout="file1";} /wt/{i++}i==3{fout="file2";} {print $0 > fout}' <filename>