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 have a simple script that accepts a CSV file and reads every row
I have a simple report that I want to export to a CSV file.
I want to have an ASP C# WebSite that loads a simple CSV File
I have a very very simple program that parses a csv file that has
I have simple SSIS package which reads data from flat file and insert into
I have an awk script that processes a csv file and produces a report
I have a VB web application that reads from a CSV file which contains
I've got a simple web-page that generates a CSV file that I want the
I have another csv file where I am trying to do a simple word
Updated to be clear. Step One: I have a XML file that I want

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.