Football formation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Football formation
# 1  
Old 10-27-2014
Football formation

I'm trying to create a perl script that will automatically fit the player's name to the formation.
For example, in my:
DR.txt
Code:
Arbeloa 200
Carvajal 190
Ramos 180

DC.txt
Code:
Ramos 200
Pepe 190
Varane 180

DL.txt
Code:
Marcelo 200
Coentrao 190
Arbeloa 180

formation.txt:
Code:
DR
DC
DC
DL
DR
DC
DC
DL

My expected output from my formation.txt will be:
Code:
DR Arbeloa 200
DC Ramos 200
DC Pepe 190
DL Marcelo 200
DR Carvajal 190
DC Varane 180
DC
DL Coentrao 190

Any help?

Last edited by Tzeronone; 10-27-2014 at 07:16 AM..
# 2  
Old 10-27-2014
For your first request, which included only the first four lines of your output equivalent to formation's content, this might work:
Code:
awk     'FILENAME != "formation"        {PL[FILENAME,++CNT[FILENAME]]=$0; next}
                                        {print $0, PL[$0,++CNT2[$0]]}
        ' DR DC DL formation
DR Arbeloa 200
DC Ramos 200
DC Pepe 190
DL Marcelo 200

This User Gave Thanks to RudiC For This Post:
# 3  
Old 10-27-2014
Quote:
Originally Posted by RudiC
For your first request, which included only the first four lines of your output equivalent to formation's content, this might work:
Code:
awk     'FILENAME != "formation"        {PL[FILENAME,++CNT[FILENAME]]=$0; next}
                                        {print PL[$0,++CNT2[$0]]}
        ' DR DC DL formation
Arbeloa 200
Ramos 200
Pepe 190
Marcelo 200

Actually the next line is "Carvajal" because "Arbeloa" is already existed in the line up. Smilie
# 4  
Old 10-27-2014
Maybe I'm lost because I'm used to American football, but I don't understand the rules that are being used to create the output you are expecting from your four given input files.

Why does this need to be done using perl? Is this a homework assignment?
# 5  
Old 10-27-2014
Quote:
Originally Posted by Don Cragun
Maybe I'm lost because I'm used to American football, but I don't understand the rules that are being used to create the output you are expecting from your four given input files.

Why does this need to be done using perl? Is this a homework assignment?
For sure it is not homework assignment. From the formation.txt,
Code:
the first row: DR. Therefore, it will take the name from DR. txt which is ARBELOA 200
the second row: DC. Therefore, it will take the name from DC. txt which is RAMOS 200
the third row: DC. Therefore, it will take the name from DC. txt which is RAMOS 200, BUT since RAMOS is already exist in the line up, it will be filled by PEPE 190
the fourth row: DL. Therefore, it will take the name from DL. txt which is MARCELO 200
the fifth row: DR. Therefore, it will take the name from DR. txt which is ARBELOA 200, BUT since ARBELOA is already exist in the line up, it will be filled by CARVAJAL 190
the sixth row: DC. Therefore, it will take the name from DC. txt which is RAMOS 200, BUT since RAMOS and PEPE are already exist in the line up, it will be filled by VARANE 180
the seventh row: DC. Therefore, it will take the name from DC. txt which is RAMOS 200, BUT since RAMOS, PEPE and VARANE are already exist in the line up, it will be blank
the eighth row: DL. Therefore, it will take the name from DL. txt which is MARCELO 200, BUT since MARCELO is already exist in the line up, it will be filled by COENTRAO 190

Because I believe PERL is efficient for text processing and I have around 3312 of formation.

Last edited by Tzeronone; 10-27-2014 at 07:21 AM..
# 6  
Old 10-27-2014
With your new formation file, this is the result:
Code:
DR Arbeloa 200
DC Ramos 200
DC Pepe 190
DL Marcelo 200
DR Carvajal 190
DC Varane 180
DC 
DL Coentrao 190

# 7  
Old 10-27-2014
Quote:
Originally Posted by RudiC
With your new formation file, this is the result:
Code:
DR Arbeloa 200
DC Ramos 200
DC Pepe 190
DL Marcelo 200
DR Carvajal 190
DC Varane 180
DC 
DL Coentrao 190

What about perl?
After I run the awk, it gives me error
Code:
C:\Program Files\GnuWin32\bin>awk 'FILENAME != "formation.txt" {PL[FILENAME,++CNT[FILENAME]]=$0; next} {print PL[$0,++CNT2[$0]]} ' DR.txt DC.txt DL.txt formation.txt
awk: 'FILENAME
awk: ^ invalid char ''' in expression


Last edited by Tzeronone; 10-27-2014 at 11:53 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Programming

Not a repeated question (Perl Script Create Football Formation)

https://www.unix.com/programming/252468-perl-script-create-football-formation.html https://www.unix.com/members/43551.html, it is not repeated question. please read it before u block my question. Unblock it for me. Thanks:mad: (0 Replies)
Discussion started by: Tzeronone
0 Replies

2. Programming

Perl script to create football formation

I need help to create varieties of football formation. The available positions are: GK SW DR DC DL WBR DM WBL MR MC ML AMR AMC AML ST But the conditions are: a. the maximum number in 1 formation: GK is 1 SW is 1 (1 Reply)
Discussion started by: Tzeronone
1 Replies

3. UNIX for Advanced & Expert Users

Data formation

I have a data like as follows, I need to format it as shown in as below. Request you to help me here ? I/P aa|3|1 aa|4|2 bb|3|1 bb|4|1 cc|3|26 cc|4|1 O/P aa|3|1|4|2 bb|3|1|4|1 cc|3|26|4|1 Thanks, Srikanth (5 Replies)
Discussion started by: srikanth38
5 Replies

4. Shell Programming and Scripting

Perl string formation from array

HI I ma using perl programming my perl is like this $InputFile = $ENV{UDE_TMP} . "/" ."cre_fmr_gen.temp_data_file_gen.dat"; @duplicates = `cat $InputFile | cut -d "|" -f 1,1 | sort | uniq -c | awk '{ if(\$1>1) {print \$2;}}'`; my $cusiplist ; foreach $cusip (@duplicates) {... (1 Reply)
Discussion started by: ptappeta
1 Replies

5. Shell Programming and Scripting

Formation of sql files

Dear Experts, I have a scenario where I have to form sql queries in a file using echo command. I have file1 which has more than 10 lac numbers. For each Number in file 1, I need to create 5 sql queries resulting in 50 lac queries totally. For doing this I use the below simple method, for i... (5 Replies)
Discussion started by: Naga06
5 Replies

6. Shell Programming and Scripting

date command op formation

Dear All I am facing below mention problem plz suggest me solution. Op of date command: > date Tue Jan 1 12:17:52 IST 2008 Now i want Jan 1 12: or Jan 1 12 op in some another variable. I had tried awk but if give me problem when there is date comes in 2 digit i.e. greater that 9.... (1 Reply)
Discussion started by: jaydeep_sadaria
1 Replies
Login or Register to Ask a Question