file

i have a file containing data in following format

email,username,date

i want to creat a file containing just the email address

i know how to do by opening file, reading .....

is there a simple way of doing that using some unix commands in my perl script
LVL 1
shahrahulbAsked:
Who is Participating?
 
jmcgOwnerCommented:
If I read you correctly, you think you know how you'd do this in Perl, but you want to know how to do it externally to Perl using shell commands? Is that right?

system( "sed -e s/,.*// $existingfile >$newfile");

will trim out everything from the first comma to the end of the line on each line in the file named in $existingfile and place the results in a file named by $newfile.
0
 
shahrahulbAuthor Commented:
ya, u understood me correctly.....let me try this....
0
 
shahrahulbAuthor Commented:
It worked!!!!

thanks.
0
 
ozoCommented:
But it won't work if you have a directory named "s" containing a directory that starts with ",."
0
 
jmcgOwnerCommented:
Ozo's right, of course. Sloppy quoting on my part:

system "sed -e 's/,.*//' $existingfile >$newfile";
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.