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

  • Home
  • SEARCH
  • 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 8511795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:06:21+00:00 2026-06-11T04:06:21+00:00

I have many csv files that I need to clean ( replace ponctuation by

  • 0

I have many csv files that I need to clean ( replace ponctuation by space and replace certain words by others…) My csv files have two columns and in each one I replace some caracters by others. For exemple, in the first column I replace ; by xxx and in the second column I replace ; by ppp. To do that, I have two perl codes in regex and I slice one csv file on two files : file 1 = first column and file 2 = second column and I run the code for the first columns on the file of the first colums ….
It’s not a good way at all :s !!!

So how can I have one code in which the first condition run on the first column and the second condition on the second column of the SAME file ?

CSV example :
http://dbpedia.org/resource/Berenguer_de_Cru%C3%AFlles Berenguer de Cruïlles
http://dbpedia.org/resource/Berenguer_de_Cru%C3%AFlles Berenguer de Cruïlles

The IRI is the first column and the names are in the second one.

Perl code in regex for the first column :

use strict;
use warnings;

open(IN,$ARGV[0]);
open(OUT,">RES_xxx.txt");
while(my $l = <IN>)
{
 chomp($l);
     $l =~ s/http:\/\//_/g;
     $l =~ s/,/vvv/g;
     $l =~ s/"/=/g;
     $l =~ s/'/#/g;
     $l =~ s/\(/ééé/g;
     $l =~ s/\)/èèè/g;
     $l =~ s/%/zzz/g;

     print OUT "$l\n";
}
close(IN);
close(OUT);

Perl code in regex for the second column :

   #! usr/bin/perl

    use strict;
    use warnings;

    open(IN,$ARGV[0]);
    open(OUT,">RES_xxx.txt");
    while(my $l = <IN>)
    {
     chomp($l);
     $l =~ s/\(.+\)/ /g;
     $l =~ s/'/ /g;
     $l =~ s/"/ /g;
     $l =~ s/,/ /g;
     $l =~ s/\./ /g;
     $l =~ s/:/ /g;
     $l =~ s/;/ /g;
     $l =~ s/!/ /g;
     $l =~ s/\?/ /g;
     $l =~ s/-/ /g;
     $l =~ s/_/ /g;
     $l =~ s/{/ /g;
     $l =~ s/}/ /g;
     $l =~ s/\+/ /g;
     $l =~ s/=/ /g;

     print OUT "$l\n";
    }
    close(IN);
    close(OUT);

Thank you !

  • 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-06-11T04:06:23+00:00Added an answer on June 11, 2026 at 4:06 am

    You could do that by parsing your file in two steps:

    1. on the first step, you replace the ; in the first column of the original file;

    2. on the second step, you replace the ; in the second column on the output of the first step.

    This should be easily done from your current solution: I suppose you have a regex to match the first column and the second column. You can simply change those regex so that instead of matching the first or second columns, they replace within that column.

    If you provide more details about your files and how you currently split the two columns, I might provide some concrete example.

    EDIT:

    Since it seems that you only have two columns and each does not contain any commas, you could do like this:

    1. parse the file line by line;

    2. split the line at the , (separator between the columns);

    3. on each part you got at step 2, apply the regex to replace what you want.

    E.g.:

    my $file = 'file.csv';
    open(my $fh, '<', $file) or die "Can't read file '$file' [$!]\n";
    while (my $line = <$fh>) {
      chomp $line;
      my ($firstCol, $secondCol) = split(/,/, $line);
      $firstCol =~ s/;/xxx/g;
      $secondCol =~ s/;/yyy/g;
      print "$firstCol, $secondCol\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file with many rows in which I need to update/replace
I have many different csv files that I would like to convert in to
I have two csv files which store an id and some associated fields that
I have many PowerPoint presentations that I need to be able to add to
I have a need to import a number of CSV files into corresponding tables
I have a csv file which has two columns, a numeric ID ( IDVAR
I have two .csv files containing correlation matrices exported from R. One file contains
I have many directories with some sub-directories that need to be deleted. Is there
I'm parsing a large csv files - about 500 meg (many rows, many columns).
I have a list of (many) employees in Excel/csv who take sick days, listed

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.