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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:23:57+00:00 2026-05-17T23:23:57+00:00

I am attempting to process a plain text file. It is basically an index

  • 0

I am attempting to process a plain text file. It is basically an index of names and associated number fields formatted like so:

Nowosielski, Matthew, 484, 584, 777
Nowosielski, Matthew, 1151
Nunes, Paulino, 116
Nussbaum, Mike, 1221, 444,
Nussbaum, Mike, 156

Which I would like to process into this

Nowosielski, Matthew, 484, 584, 777, 1151
Nunes, Paulino, 116
Nussbaum, Mike, 156, 444, 1221

As you can see, the lines do not end consistently: some are likely to be whitespace, some newlines and some with commas. Effectively, I need to merge lines beginning with duplicated full-names, discarding the redundant name entry while merging and preserving the numerical order of the numerical fields.

My gut tells me to learn either some quick perl or awk, but my skill-set is, for both, empty. I looked into both, and after some searching and reading haven’t been able to find a clear or clean path to a solution.

My question thus is: what would be the best tool for the job that I might learn efficiently and just enough to complete this task? Also, given the suggested tool, are there any suggestions on how to approach the problem?

I can just edit this file by hand, of course, but that’s not very interesting and seems to be a very stupid, ham-fisted approach to the problem. I’m taking this task as an excuse to learn a bit about text processing as it feels like a problem for which there’s probably a good, existing tool.

Any pointers?

  • 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-17T23:23:57+00:00Added an answer on May 17, 2026 at 11:23 pm

    As Brian said, use a hash table. The following removes newlines, splits each record on commas, uses the “last name, first name” original form as a key to a hash, pushes the remaining values into an array and uses a reference to said array as the value to the above key.

    Then it just iterates over the key/value pairs in the hash and formats accordingly.

    Amended solution – sorting numbers, omitting middle names, and sorting output

    #!/usr/bin/env perl
    use strict;
    use warnings;
    
    my %merged;
    
    while (my $record = <DATA>) {
        chomp $record;
        my ($lname, $fname, @stuff) = split /[, ]+/, $record;
        push @{ $merged{"$lname, $fname"} }, grep { m/^\d+$/; } @stuff;
    }
    
    foreach my $name (sort keys %merged) {
        print $name, ", ", join( ', ', sort { $a <=> $b } @{$merged{$name}}), "\n";
    }
    
    __DATA__
    Nowosielski, Matthew, 484, 584, 777
    Nowosielski, Matthew, 1151
    Nunes, Paulino, 116
    Nussbaum, Mike, 1221, 444,
    Nussbaum, Mike, 156
    Nowosielski, Matthew, Kimball, 485, 684, 277
    

    Amended output

    Nowosielski, Matthew, 277, 484, 485, 584, 684, 777, 1151
    Nunes, Paulino, 116
    Nussbaum, Mike, 156, 444, 1221
    

    Original solution

    #!/usr/bin/env perl
    use strict;
    use warnings;
    
    my %merged;
    
    while (my $record = <DATA>) {
        chomp $record;
        my ($lname, $fname, @stuff) = split /,/, $record;
    
        push @{ $merged{"$lname, $fname"} }, @stuff;
    }
    
    while (my ($name, $stuff) = each %merged) {
        print $name, join( ',', @$stuff), "\n"; 
    }
    
    __DATA__
    Nowosielski, Matthew, 484, 584, 777
    Nowosielski, Matthew, 1151
    Nunes, Paulino, 116
    Nussbaum, Mike, 1221, 444,
    Nussbaum, Mike, 156
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When attempting to call functions in math.h , I'm getting link errors like the
When attempting to open a project from source control on a newly formatted pc,
I am learning about cryptographic algorithms and in the process am attempting to implement
I have a large text file of records, each delimited by a newline. Each
All, I'm currently in the process of attempting to create a repeatable process for
I'm attempting to build a project in Eclipse CDT and the build process fails
Before attempting to resize an image in PHP using libGD, I'd like to check
Attempting to insert an escape character into a table results in a warning. For
Attempting to print out a list of values from 2 different variables that are
Attempting to deploy a MOSS solution to a UAT server from dev server for

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.