how can i delete columns beginning and ending with parenthesis in a file
Expectd Input - content of input.txt
ABC (BCD) EFG
BCD (ABC) (BCD)
DEF BCD (ABC)
EFG HI(JKL)
ABC EFG (HI JK) LMN
Expectd Output -- content of output.txt
ABC EFG
BCD
DEF BCD
EFG HI(JKL)
ABC EFG LMN
Just thought id add one more sample input for clarity.
ABC (lll) INTEGER NOT NULL -3
EDG (FK) (lll) INTEGER NOT NULL -3
HIJ (nn ooo) CHAR(16) NOT NULL 'Not Provided'
KLM (ppp) VARCHAR(75) NOT NULL 'Not Provided'
NOP (qqq) VARCHAR(75) NOT NULL 'Not Provided'
QARD (rrr) DATE NOT NULL '1900-01-01'
QRS (sss) DATE NOT NULL '1900-01-01'
TUV DATE NOT NULL '1900-01-01'
WXY (uuu) CHAR(1) NOT NULL 'N'
Based on the solution from @slitvinov:
That to an
.awk
file andawk -f foo.awk foo.txt
gives:But I think it could be done simpler...
The simplest thing that I can assemble is:
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.
Usage
awk '{print $0" "}' foo.txt | awk -f foo.awk
foo.awk