how can i delete columns beginning and ending with parenthesis in a file

前端 未结 3 625
无人共我
无人共我 2021-01-29 00:58

how can i delete columns beginning and ending with parenthesis in a file

Expectd Input - content of input.txt

ABC (BCD) EFG          


        
3条回答
  •  日久生厌
    2021-01-29 01:36

    Based on the solution from @slitvinov:

    BEGIN {
        RS = "[[:space:]]"
        ORS = ""
        eat = 0
    }
    
    /^\(.*\)$/ {
        next
    }
    
    /^\(/ {
        eat = 1
        next
    }
    
    /\)$/ {
        if (eat) {
            eat = 0
            next
        }
    }
    
    {
        if (eat)
            next
        print $0 RT
    }
    

    That to an .awk file and awk -f foo.awk foo.txt gives:

    ABC EFG    
    BCD 
    DEF  BCD  
    EFG HI(JKL)
    ABC EFG LMN
    

    But I think it could be done simpler...

提交回复
热议问题