views:

73

answers:

2

Hi all,

I was wondering if it would be possible to remove columns within a data file that contain any parenthesis that can be contained in ANY column. For example

...
John Doe (Tech Department) 09/12/2009 555-555-5555
Jane Smith 09/12/2009 555-555-5555 (Suspended)
Alfred doe 555-555-5555 (Vacation) 09/09/2011
...

So then I would like the output to look like

...
John Do 09/12/2009 555-555-5555
Jane Smith 09/12/2009 555-555-5555
Alfred doe 555-555-5555 09/09/2011
...

I was thinking of using a wildcard for the text in between the parenthesis? something like /(*)/ ?

Thanks for any help,

Tomek

+2  A: 
$ cat file
John Doe (Tech Department) 09/12/2009 (somethign else) 555-555-5555
Jane Smith 09/12/2009 555-555-5555 (Suspended)
Alfred doe 555-555-5555 (Vacation) 09/09/2011

$ awk -vRS=")" -F"(" '{ for(i=1;i<=NF;i+=2) {print $i}}' ORS="" file
John Doe  09/12/2009  555-555-5555
Jane Smith 09/12/2009 555-555-5555
Alfred doe 555-555-5555  09/09/2011

$ sed -r 's/\(.[^)]*\)//g' file
John Doe  09/12/2009  555-555-5555
Jane Smith 09/12/2009 555-555-5555
Alfred doe 555-555-5555  09/09/2011

$ awk '{gsub(/\(.[^)]*\)/,"") }1' file
John Doe  09/12/2009  555-555-5555
Jane Smith 09/12/2009 555-555-5555
Alfred doe 555-555-5555  09/09/2011
ghostdog74
@ghostdog74 worked like a charm, thanks ghost. I have to wait 7 minutes to accept your answer 8)
Tomek
would it be possible to explain whats going on in that line? more specifically -vRS? ORS?
Tomek
`RS=")"` means set record separator to `)`.. `-F"("` means set field separator to `(`. then go through the odd numbered fields to get your information. At the same time set output record separtor ORS to nothing. This is a more "complicated" method. Just use the regex method from the other solutions.
ghostdog74
+1  A: 

If Perl is okay, you can do:

$ cat file
John Doe (Tech Department) 09/12/2009 555-555-5555
Jane Smith 09/12/2009 555-555-5555 (Suspended)
Alfred doe 555-555-5555 (Vacation) 09/09/2011

$ perl -pe 's/\(.*?\)//g' file    
John Doe  09/12/2009 555-555-5555
Jane Smith 09/12/2009 555-555-5555 
Alfred doe 555-555-5555  09/09/2011
codaddict