Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 620135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:43:50+00:00 2026-05-13T18:43:50+00:00

I am looking for a way to read an input file and print only

  • 0

I am looking for a way to read an input file and print only select lines to an output file in Perl. The lines I want to print to the output file all begin with xxxx.xxxx.xxxx, where x is an alphanumeric character (the periods are periods, not wildcards). The lines do not all have the same ending, if that makes a difference. I’m thinking something like the following (the condition of the if statement is all that is really missing as far as I can tell).

open(IN, "<$csvfile");
my @LINES = <IN>;
close(IN);
open(OUT, ">$csvnewfile");
print OUT @LINES if ([line starts with xxxx.xxxx.xxxx]);
close(OUT);

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:43:51+00:00Added an answer on May 13, 2026 at 6:43 pm

    Here is a better way to loop through your lines. It avoids loading your whole input file into memory at once:

    use strict;
    use warnings;
    
    open my $fhi, '<', $csvfile    or die "Can not open file $csvfile: $!";
    open my $fho, '>', $csvnewfile or die "Can not open file $csvnewfile: $!";
    while (<$fhi>) {
        print $fho $_ if m/^ \w{4} \. \w{4} \. \w{4} /x;
    }
    close $fho;
    close $fhi;
    

    Keep in mind that the \w character class also includes underscores. To avoid underscores:

    print $fho $_ if m/^ [a-z\d]{4} \. [a-z\d]{4} \. [a-z\d]{4} /xi;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a way to read the standard output byte by byte
I am looking for a way to branch (tee) the input read from an
I am looking to see a simple way to read from and write to
I'm looking for a way if you know the location where to read the
Please note - I am not looking for the right way to open/read a
I'm looking for a faster way to calculate GC content for DNA strings read
I want to iterate over each line of an entire file. One way to
I'm wondering if there is a way that I can read user input from
I have been looking for a way to do this all around the internet
I am looking for a (correct) way to read and write to a linux

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.