1

在这里,我尝试将第一个和第二个 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)

但这是打印整个东西。

4

1 回答 1

1

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

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

于 2013-05-07T05:04:10.353 回答