Perl script to verify that a value is present in an array (list)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl script to verify that a value is present in an array (list)
# 1  
Old 07-09-2013
Perl script to verify that a value is present in an array (list)

I have 2 files , i need compare both files field by field, and in the fourth field some value will be interchaged and some value will be **.
ex:
Code:
file1 john|0.0|4|**:25;JP:50;UY:25
file2 john|0.0|4|JP:50;**:25;UY:25


Last edited by Don Cragun; 07-09-2013 at 04:45 AM.. Reason: Add CODE tags.
# 2  
Old 07-09-2013
Post desired output for those two sample files.
# 3  
Old 07-09-2013
And what are you expecting the output to be when you compare these two files?

If the same data appears multiple times (e.g., 25 apears twice in the 4th field of both files), does it matter if they appear the same number of times or only that the given value is present at least once? (Of course, this assumes that colon and semicolon are subfield separators in the 4th vertical bar separated field. You need to explicitly state what your field separators are since there are clearly other possibilities with the minimal sample you have shown us!)

How about showing us an example where some fields do not match and show us the desired output.
# 4  
Old 07-09-2013
Output : both files are similiar then print first field along with PASS in file3 .
ex John -->PASS .
else print john-->FAIL, in 4th fourth field(mismatch).

---------- Post updated at 02:53 PM ---------- Previous update was at 02:19 PM ----------

suppose file 2, fourth field is JP:40;**:30;UY:30
then output file3 should be john->FAIL, fourth field. because file1 fourth field has
john|0.0|4|**:25;JP:50;UY:25
Moderator's Comments:
Mod Comment PLEASE USE CODE TAGS. We can't add them for you because you are not at all clear as to what the desired output should be. Furthermore, it is your job to make your request understood; not a moderator's job to edit your posts to make them understandable.

Last edited by Don Cragun; 07-09-2013 at 04:22 PM..
# 5  
Old 07-09-2013
Quote:
Originally Posted by veeruasu
Output : both files are similiar then print first field along with PASS in file3 .
ex John -->PASS .
else print john-->FAIL, in 4th fourth field(mismatch).

---------- Post updated at 02:53 PM ---------- Previous update was at 02:19 PM ----------

suppose file 2, fourth field is JP:40;**:30;UY:30
then output file3 should be john->FAIL, fourth field. because file1 fourth field has
john|0.0|4|**:25;JP:50;UY:25
Once more: PLEASE USE CODE TAGS. WIth what you have specified above, we have no idea whether the output you want in file3 is:
Code:
john->FAIL, fourth field. because file1 fourth field has john|0.0|4|**:25;JP:50;UY:25
john->FAIL, fourth field.
john-->FAIL, in 4th fourth field(mismatch).
john-->FAIL, in 4th fourth field
john-->FAIL
john -->FAIL
john ->FAIL
    or
john->FAIL

or something completely different.

You also have not specified what similar means. Is john|0.0|4|**:25;JP:50;UY:25 similar to john|0.0|4|JP:50;**:25;UY:25, john|0.0|4|JP;50;**;25;UY;25, john|0.0|4|JP:25;**:25;UY:50, and john|0.0|4|JP:50;**;UY:25? They all contain the same numbers. They all contain the same character strings. They all contain "**". Please explain what criteria is used to determine if they are similar?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl next if @array (exclude a list of values)

I'm trying to exlude a list of values with perl to process while reading in a file. Is there a way to use the next if with a list? Example: @array = qw(val1 val2 val3 val6); while (<>) { next if $_ =~ @array; # values I don't want to process here print; # process the rest here }... (8 Replies)
Discussion started by: timj123
8 Replies

2. UNIX for Advanced & Expert Users

Help in perl script Array.

hi Team, i need a help in perl , i need to get values(10 rows +) from perl GUI and insert those values into oracle table. am trying to achive this in Perl array, can you please help me on this. thanks senthil (1 Reply)
Discussion started by: senkerth
1 Replies

3. Shell Programming and Scripting

calling a shell script present on another server using perl script.

Hi, I am working on a sever A. I want to write a perl script to execute a shell script persent on the server B. please help me in this. thanks in advance. (3 Replies)
Discussion started by: anandgodse
3 Replies

4. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

5. Shell Programming and Scripting

Script to list files not present in audio.txt file

I am having following folder structure. /root/audios/pop /root/audios/jazz /root/audios/rock Inside those pop, jazz, rock folders there are following files, p1.ul, p2.ul, p3.ul, j1.ul, j2.ul, j3.ul, r1.ul, r2.ul, r3.ul And I have a file named as "audio.txt" in the path /root/audios,... (11 Replies)
Discussion started by: gopikrish81
11 Replies

6. Shell Programming and Scripting

How to get list of user into an array in perl script

Hi, cut -d: -f1,3 /etc/group >rpt.out I have a doubt in perl. right i am getting list of group user id into rpt.out file. instead i need to store it as an array in perl script. could you please tell me how can i get list of user into an array in perl script.. thanks in advance. (1 Reply)
Discussion started by: solo123
1 Replies

7. Shell Programming and Scripting

How to export an array to perl script?

hi all...... i want to use an array ,declared in bash, in embedded perl script. is there any way to export whole array so that i can use it '$ENV{}' or something.. thanx in advance!! regards, prayush (1 Reply)
Discussion started by: tprayush
1 Replies

8. Shell Programming and Scripting

How to run a loop for assigning strings which are present in a file to an array

Hi Forum, I am struggling with the for loop in shell script. Let me explain what is needed in the script. I have a file which will conatin some strings like file1 place1 place2 place3 checkpoint some other text some more text Now what my requirement is the words ... (2 Replies)
Discussion started by: siri_14
2 Replies

9. Shell Programming and Scripting

How to check the variable is present in array or not ?

Hi , I am trying to check wether the variable is present in the array. please see the below code .when ever i do this its taking only the first value of the array . please advise. ###Code Snnipet ### #!/bin/ksh set -xv if ]; then echo " you have Specified the ORG ID - $1 " ... (1 Reply)
Discussion started by: padhu.47
1 Replies

10. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies
Login or Register to Ask a Question