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

前端 未结 3 687
无人共我
无人共我 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:31

    Usage
    awk '{print $0" "}' foo.txt | awk -f foo.awk

    foo.awk

    BEGIN {
        RS=ORS=" "
    }
    
    {
        n=length($0)
        if (!n) next
        split($0, s, "")
    }
    
    s[1]=="(" && s[n]==")" {
        # it is column like (abcd), skip it
        next
    }
    
    s[1]=="(" {
        # stop printing
        f=1
    }
    
    !f {
        print $0
    }
    
    s[n]==")" {
        # start printing again
        f=0
    }
    

提交回复
热议问题