Link to home
Start Free TrialLog in
Avatar of tomatocans
tomatocans

asked on

Join, Sequence Number, and Two Ouputs

You have an input file with over a million lines like so :

0998|1999|1000|ATL|SEA|H|USAIR|2725|3002|0845


The first ouput file:

Assigns a sequence number to each line that is unique, combines the first three fields into one, only uses the last two digits of field 2, defaults the ouput of 2 to 99 if is is blank, puts a "_" after field 2, and also prints out field 6.

For example:

the above line would be:

00000001|099899_1000|USAIR


The second output file assigns a sequence number if fields 4,5,6,7,8,9,10 are unique.

For example the ouput would be:

00000001|ATL|SEA|H|USAIR|2725|3002|0845


How would u write this in perl

Any help appreciated:

Thanks
Avatar of tomatocans
tomatocans

ASKER

Adjusted points from 25 to 50
Avatar of ozo
$sequence='0000000';
while( <> ){
  @field=split/\|/;
  print join'|',$sequence++,$field[0].substr($field[1]||99,-2)."_$field[2]","$field[6]\n";
}
ASKER CERTIFIED SOLUTION
Avatar of PC_User321
PC_User321

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTW tomatocans, many of your questions remain ungraded.
I suggest you go through all your questions and awards points to people who have given correct answers/comments, or if no one is correct, then delete the question or add more information.
My solutions can be streamlined slightly:

In each script the two lines in the form of
     unless (defined($CheckDup{$Line})) {
    $CheckDup{$Line} = 1;
   
can be replaced with
  unless (++$CheckDup{$Line} > 1) {
   
Thanks