Click to See Complete Forum and Search --> : need help with stripping chars from data


bigmac99
02-11-2006, 02:34 PM
I have a text file that I need to strip some data out of. Here is what I need to do:

I have a csv file with a column that says email address - the data is formatted like this:
Charles McNeill (cmcneill@charlesmcneill.com)
I need to figure out how to strip every entry in this field so that the only thing left is what is in the ( ) - without the ( ).

The data is not the same length either, meaning it contains:
Charles McNeill (cmcneill@luminawebhosting.com)
Bigmac (charles@luminawebhosting.com)
charlesmac (charles@stoptheblock.com)

Can anyone help?

Thanks in advance.
Charles McNeill

flukshun
02-11-2006, 03:34 PM
i.e. you just want to get all the email addresses?

happybunny
02-11-2006, 03:40 PM
cat filename|cut -d ( -f1 >newfile

completely off the top of my head however with no way to test at the moment


man thats ugly:

cat filename|cut -d "(" -f2 |sed s/\)/" "/ > newfile.

There's got to be a better way, but that might do it if you're in a hurry.

bigmac99
02-11-2006, 04:05 PM
yes, I want to just pull out the email address...but keep the rest of the file intact.

ie...the email address is field 5 of 7 fields in the file, I want the rest of the file left alone.

-Charles

bburton
02-12-2006, 01:38 AM
Here's another way to do it. Perl script below:

#!/usr/bin/perl

while (<>)
{
/\((.*)\)/;
print $1 . "\n";
}


It can be used in the following way:


$./perlscript.pl < file.txt


If you want to just strip the e-mail address off of the original file (I'm not sure exactly what you're wanting to do) you could do it with the following Perl script:


#!/usr/bin/perl

while (<>)
{
s/\(.*\)/\(\)/g;
print;
}


Have a nice day.

edit: simplified scripts

bigmac99
02-13-2006, 11:51 AM
bburton, that works, it shows the output on the screen, is there anyway to get it written back to the file? this is a comma delimited csv file, if that matters.

Thanks for your help.
-Charles

bigmac99
02-13-2006, 12:14 PM
oops... bburton, I mean your first example shows what I want to see on the screen, can we write it back into the file in the same location?

-Charles

bburton
02-13-2006, 03:52 PM
oops... bburton, I mean your first example shows what I want to see on the screen, can we write it back into the file in the same location?

-Charles


$cat file.txt | ./perlscript.pl > file.txt