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

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

    The simplest thing that I can assemble is:

    perl -pe 'BEGIN { undef $<; } s/\s(\(.*?\)(\s))+/\2/cgs' foo.txt
    

    Sorry for Perl but it's in POSIX and it has regular expressions powerful enough to cover the case.

    Ah, and it can't handle if the file starts with a parenthesis. If it ends with one, it's fine as long as there's newline after it. If that's a problem, then the easiest solution would be to just add a temporary space.

提交回复
热议问题