Posted on 2005-04-13
Last Modified: 2010-03-05
i have a file containing data in following format


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
Question by:shahrahulb
    LVL 20

    Accepted Solution

    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.
    LVL 1

    Author Comment

    ya, u understood me correctly.....let me try this....
    LVL 1

    Author Comment

    It worked!!!!

    LVL 84

    Expert Comment

    But it won't work if you have a directory named "s" containing a directory that starts with ",."
    LVL 20

    Expert Comment

    Ozo's right, of course. Sloppy quoting on my part:

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

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now