A script to format a file (ideally PERL)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A script to format a file (ideally PERL)
# 8  
Old 09-21-2015
I have modified the script on the same below link, OR condition(|) was missing for one of the statement - copy paste type error, apologies for the same. Tested working very well
Perl - Need a Perl code for the below input and output
This User Gave Thanks to kidSandy For This Post:
# 9  
Old 09-21-2015
Code:
#!/usr/bin/perl

use strict;
use warnings;

# map relationships to gender.
# accommodate misspelling of Daughter
my %gender = (
    'Father', '[M]',
    'Mother', '[F]',
    'Daugther', '[F]',
    'Daughter', '[F]',
    'Son', '[M]',
    'Child', '[]',
);

my @parents;
my %children;

# read kylle345.file file line by line
# change to the actual file name to read from
open my $fh, '<', 'kylle345.file' or die;

# map parents and children per family into two categories
while(<$fh>){
    chomp;
    my ($family_id, $person) = split('-\w+\s+');
    my ($id, $relation, $name) = split('\s+', $person, 3);
    if($relation =~ /Father|Mother/) {
         push @parents, [$family_id, $id, "[$name]$gender{$relation}"];
         next;
    }
    push @{$children{$family_id}}, [$id, "[$name]$gender{$relation}"];
}
close $fh;

# report maps of parents and children
for my $session (@parents){
    my ($f, $i, $p) = @{$session};
    for my $child (@{$children{$f}}) {
        print "$f-$i$child->[0]_$p - $child->[1]\n";
    }
}

Code:
$ perl kylle345.pl
USIM1357-11A11C_[Jim Smith][M] - [Jack Smith][M]
USIM1357-11B11C_[Jane Smith][F] - [Jack Smith][M]
V106866-12A12B_[Ralph Davis][M] - [Randy Davis][]
V106864-14A14B_[Jane Jones][F] - [Jim Jones][M]
V106879-15A15B_[Andre Busby][M] - [Jenny Busby][F]
V106611-2A2B_[Kyle Mike][M] - [Evan Mike][M]
V106611-2A2C_[Kyle Mike][M] - [Bob Mike][M]
V106611-2A2D_[Kyle Mike][M] - [Jane Mike][F]

This User Gave Thanks to Aia For This Post:
# 10  
Old 09-22-2015
Has anyone thought about making a data entry form that would handle all of the special cases, as well as verify that the data is correct as its being entered?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX/PERL script to convert XML file to pipe delimited format

Hello, I need to get few values from a XML file and output needs to be written in another file with pipe delimited format. The Header & Footer of the Pipe Delimited file will be constant. The below is my sample XML file. I need to pull the values in between the XML tags <Operator_info to... (15 Replies)
Discussion started by: karthi1305561
15 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

Perl -- Script to re-format data

Hi, I have a file with data in the following format BOX -1.000000 -1.000000 0.000000 30.00000 14.00000 0.1000000 0.000000 0.000000 0.000000 0.000000 0.000000 CYLINDER 3.595000 2.995000 0.000000 0.5100000 2.000000 Z 0.000000 0.000000 0.000000 I want to convert these files... (1 Reply)
Discussion started by: lost.identity
1 Replies

4. Shell Programming and Scripting

perl script to check the mail ids in the correct format or not

Hi Folks, I have few mailids in a text file and need to check whether the mailid is in correct format or not. If just to check whether the string is a mailid or not there is a perl module Email::Valid to do the business or we can implement our own logic. But the mail_ids I am having is... (4 Replies)
Discussion started by: giridhar276
4 Replies

5. Shell Programming and Scripting

Help with perl script to output data in table format...

Hello, I need help with a perl script that will process a text file and match virtual server name to profile(s). the rest will be ignored. Virtual server name follows the word "virtual" in the begging of the line. There could be multiple profiles assigned to one virtual server. For example, ... (3 Replies)
Discussion started by: besogon
3 Replies

6. Shell Programming and Scripting

Perl one-liner convert to script format problem asking

Input_file_1: ABC1 DEF11 ABC3 DEF7 ABC7 DEF36 Input_file_2: DEF7 light 23 DEF11 over 2 DEF11 over 1 DEF17 blue 0 Perl one-liner that join two input file based on columns sharing a value (In this example, column 2 in Input_file_1 and column 1 in... (3 Replies)
Discussion started by: perl_beginner
3 Replies

7. Shell Programming and Scripting

Perl Script for reading table format data from file.

Hi, i need a perl script which reads the file, content is given below. and output in new file. TARGET DRIVE IO1 IO2 IO3 IO4 IO5 ------------ --------- --------- --------- --------- --------- 0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies

8. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

9. Shell Programming and Scripting

Format text to bold from perl script to csv

Hi everyone, is there any way in perl using which we can print the selective words in bold when we write the output to a csv file? Please find the example below 1. Filename: A 2. name age 12 3. city add 23 Line1 should only be bold. Outputs from other files being read in the... (2 Replies)
Discussion started by: ramakanth_burra
2 Replies

10. Shell Programming and Scripting

how to display the output file in an html format using perl

Hi, I have written a perl script to dispaly some statements from a file but i want the output statements to be dispalyed in an HTML format.Is it possible for me to do in perl scripting? Please help me with ur thoughts. Thanks In Advance Meva. (1 Reply)
Discussion started by: meva
1 Replies
Login or Register to Ask a Question