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 6025875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:21:50+00:00 2026-05-23T04:21:50+00:00

I have a simple .csv file that has that I want to extract data

  • 0

I have a simple .csv file that has that I want to extract data out of a write to a new file.

I to write a script that reads in a file, reads each line, then splits and structures the columns in a different order, and if the line in the .csv contains ‘xxx’ – dont output the line to output file.

I have already managed to read in a file, and create a secondary file, however am new to Perl and still trying to work out the commands, the following is a test script I wrote to get to grips with Perl and was wondering if I could aulter this to to what I need?-

open (FILE, "c1.csv") || die "couldn't open the file!";
open (F1, ">c2.csv") || die "couldn't open the file!";

#print "start\n";

sub trim($);

sub trim($)
{
    my $string = shift;
    $string =~ s/^\s+//;
    $string =~ s/\s+$//;
    return $string;
}

$a = 0;
$b = 0;
while ($line=<FILE>)
{
    chop($line);

    if ($line =~ /xxx/)
    {
        $addr = $line;
        $post = substr($line, length($line)-18,8);
    }
    $a = $a + 1;
}

print $b;
print " end\n";

Any help is much appreciated.

  • 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-23T04:21:50+00:00Added an answer on May 23, 2026 at 4:21 am

    To manipulate CSV files it is better to use one of the available modules at CPAN. I like Text::CSV:

    use Text::CSV;
    
    my $csv = Text::CSV->new ({ binary => 1, empty_is_undef => 1 }) or die "Cannot use CSV: ".Text::CSV->error_diag ();
    
    open my $fh, "<", 'c1.csv' or die "ERROR: $!";
    $csv->column_names('field1', 'field2');
    while ( my $l = $csv->getline_hr($fh)) {
        next if ($l->{'field1'} =~ /xxx/);
        printf "Field1: %s Field2: %s\n", $l->{'field1'}, $l->{'field2'}
    }
    close $fh;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load data from a CSV file into a MySQL database, and
I am having some difficulty with importing data from a .csv file. I am
For example suppose I have 1.csv, 2.csv, ... , 20.csv. Is there a simple
I'm trying to write my flex application so that it restores the user's settings
I have simple problem as I am not much familiar with Java GUI. I
I have written a code in Python to create a transition probability matrix from
So I'm wondering, how do I execute multiple commands in CMD using C#? What
First let me appologize if my description of this is completely retarded, still learning
I've got a problem with Spork test server. If I set config.cache_classes = false
I'm a newbie to python and scrapy and I'm following the dmoz tutorial. As

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.