Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: File Manipulation - Need Advise!

by bart (Canon)
on Jan 03, 2008 at 18:07 UTC ( [id://660282]=note: print w/replies, xml ) Need Help??


in reply to Re: File Manipulation - Need Advise!
in thread File Manipulation - Need Advise!

Workout of Old Gray Bear's idea:
my %data; my $header = <>; # first line while(<>) { my($key) = split /\t/; $data{$key} = $_; } # output: print $header; foreach my $key (sort keys %data) { print $data{$key}; }
To use it as is, call the script with "file2.txt" as parameter on the command line, and redirect the script's STDOUT to "file1.txt".
perl thescript.pl file2.txt >file1.txt

Replies are listed 'Best First'.
Re^3: File Manipulation - Need Advise!
by nashkab (Novice) on Jan 03, 2008 at 18:23 UTC
    file1.txt output is the following:- COMPUTER DISTRIBUTION_ID STATUS 30F-WKS `1781183799.xxx11' IC--- 30F-WKS `1781183799.xxxx1' IC--- ADM34A3F9 `1781183799.41455' IC---
    I want COMPUTER DISTRIBUTION_ID STATUS 30F-WKS `1781183799.xxx11' IC--- ADM34A3F9 `1781183799.41455' IC---
      Like someone said in the Chatterbox: your data may not separated by tabs. Therefore, the whole record (line) would be treated as the id.

      Replace split /\t/ in my code, with split /\s+/.

      If it still won't work, then use the following code at the end, to test what's in the hash:

      use Data::Dumper; print Dumper \%data;
      and see what makes it fail.

        Bart, Its working now!!! How can open file2.txt and print to file1.txt WITHIN THE SCRIPT? Is this possible with your solution???

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://660282]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found