CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Perl or simple Linux commands for joining information in two files?: Edit Log



S3
New User

Mar 24, 2013, 6:52 PM


Views: 703
Perl or simple Linux commands for joining information in two files?

Perl or simple Linux commands for joining information in two files?

Fellow members,

So I need to address a problem and I was wondering if I should use Perl script or if I could use the Linux command line (with commands not related solely to Perl) since my Perl is poor.

I have two tab and single space-delimited lists saved as text files.

The first file, a.txt, has data in which one line, which I call an entry, is arranged as follows:


Zip code house/residential number unique name.

(Some entries are tab-delimited while others are delimited by a single space.)

The first column is zip code, second is residential, and third is a unique name.

There are over 30,000 entries in this file.

Second file, t.txt, has two columns or one line/entry is composed as:

Unique name statistical number.

It, too, is tab-delimited and single-space delimited. There are less than 20,000 entries.

What I want to do is match unique names in t.txt to those in a.txt, so that my final outfile has:

[Unique name from t.txt] [statistical number] [zip code] [residential/house number].

The outfile must be tab-delimited. Order of information does not matter as long as information corresponds correctly to unique name in t.txt.

Since all entries are not delimited the same, I don’t know how to start feeding these different files into different hashes with the unique names as keys. (Should I use sed on the command line to substitute single spaces with tab spaces?) After reading each file into a separate hash, the code can be this?


open($FH,”<t.txt”) or die “File no open\n”;
while (<$FH>){
($tnamekey, $snumber) = split (/\+/,);
$thash{$tnamekey} = $snumber;
}

close($FH);

open($FH,”<a.txt”) or die “File no open\n”;
while (<SFH>){
??????????????????????????
$ahashkey{$anamekey} = ??????????

}

Close($FH);


$i = 0;

Foreach $tnamekey {
If ($tnamekey eq $anamekey) {
open($FH,”>>outfile”) or die “File no open\n”;
print “$tnamekey $snumber ?????????;
$i++;
}
}

Close($FH);


?????? = totally lost on what to write

I welcome any help in my lost state.

Thank you.

P.S. How do I use the code tag/function?


(This post was edited by S3 on Mar 24, 2013, 7:04 PM)


Edit Log:
Post edited by S3 (New User) on Mar 24, 2013, 7:00 PM
Post edited by S3 (New User) on Mar 24, 2013, 7:04 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives