gaurav sharma
asked on
Help with Compare script
Need a script to compare two lists
ASKER
I have two text files workspace.txt and invalids.txt .Attached are both the text files. The perl script :
1. Needs to have the paths to the workspace.txt and invalids.txt as arguments like
compare_perl.pl /path/to/invalids.txt /path/to/workspace.txt
2. Check if each string in workspace.txt is present in invalids.txt. If a match is found in the invalids.txt then print
the corresponding line in invalids.txt
3. The above check in invalids.txt is to look for string between the dot(.)and colon(') at the end.
For instance in the file invalids.txt consider the line 'PACKAGE BODY: TRON2000.ts_k_jrp_300901sf sfs0_mma'
for comparison only consider the string
ts_k_jrp_300901sfsfs0_mma
4. If a match is found then print the complete corresponding line in invalids.txt like
'PACKAGE BODY: TRON2000.ts_k_jrp_300901sfsfs0_mma' is invalid
or else just print the text from workspace.txt is valid ....in this case print
ts_k_jrp_300901sfsfs0_mma is valid
4 . Finally while comparison ignore the last row in invalids.txt n this case the line
2 rows
invalids.txt
workspace.txt
1. Needs to have the paths to the workspace.txt and invalids.txt as arguments like
compare_perl.pl /path/to/invalids.txt /path/to/workspace.txt
2. Check if each string in workspace.txt is present in invalids.txt. If a match is found in the invalids.txt then print
the corresponding line in invalids.txt
3. The above check in invalids.txt is to look for string between the dot(.)and colon(') at the end.
For instance in the file invalids.txt consider the line 'PACKAGE BODY: TRON2000.ts_k_jrp_300901sf
for comparison only consider the string
ts_k_jrp_300901sfsfs0_mma
4. If a match is found then print the complete corresponding line in invalids.txt like
'PACKAGE BODY: TRON2000.ts_k_jrp_300901sfsfs0_mma' is invalid
or else just print the text from workspace.txt is valid ....in this case print
ts_k_jrp_300901sfsfs0_mma is valid
4 . Finally while comparison ignore the last row in invalids.txt n this case the line
2 rows
invalids.txt
workspace.txt
ASKER
Desired output :
Since the only first string in workspace.txt matches the string in the invalids.txt the desired output should be
'PACKAGE BODY: TRON2000.ts_k_jrp_300901sf sfs0_mma' is invalid
we_fg_hj_k_mma is valid
fd_hf_ks_kd_mma is valid
fg_cb_vn_kd_kl_mma is valid
qw_kj_lk_oi_lm_mma is valid
qw_df_vc_bh_lk_mma is valid
ts_k_jrp_3dfdssd01140_mma is valid
rtewtwert_dfsg_dafasd_mma is valid
adf_afaf_afa_afA_mma is valid
Since the only first string in workspace.txt matches the string in the invalids.txt the desired output should be
'PACKAGE BODY: TRON2000.ts_k_jrp_300901sf
we_fg_hj_k_mma is valid
fd_hf_ks_kd_mma is valid
fg_cb_vn_kd_kl_mma is valid
qw_kj_lk_oi_lm_mma is valid
qw_df_vc_bh_lk_mma is valid
ts_k_jrp_3dfdssd01140_mma is valid
rtewtwert_dfsg_dafasd_mma is valid
adf_afaf_afa_afA_mma is valid
ASKER
@WILCOXON: Thanks for your response. I was trying to clearly explain what I need.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The script works perfectly fine. Thank you for quick response. I had one last correction to make in the requirements. The strings in invalids.txt are all uppercase.
Before checking if the string in workspace.txt exists in invalids.txt , convert the all the strings in workspace.txt to uppercase.
Before checking if the string in workspace.txt exists in invalids.txt , convert the all the strings in workspace.txt to uppercase.
ASKER
@Wilcoxon: Let me know if you need anything
It should work to just change line 19 to:
if (exists $chk{uc($_)}) {
Open in new window