2014年12月16日 星期二

Get some specific items from .mt* of NCX

注意事項:
1. perl g.pl 49 <-- 帶入.mt*內重複的次數



2. 更改search_num/search_words
example 1:
$search_num = 1;
$search_words[0] = "t_en_trip_incap1";


example 2:
$search_num = 3;
$search_words[0] = "cin__din__hl_v0"; 
$search_words[1] = "cin__din__hl_v1";
$search_words[2] = "cin__din__hl_q";


 


程式主體:
#!/usr/local/bin/perl


#if ( $#ARGV < 0 ) {
# print "+=============================================+\n";
# print "| Usage : extract.pl file_type |\n";
# print "| file_type : 1 or 2 |\n";
# print "| 1 : Separated lines |\n";
# print "| 2 : Single line |\n";
# print "| |\n";
# print "+=============================================+\n";
# die "\n";
#}


## CQHLBNCLKX4_cE_nonprop_list CQHLBNCLKX4_cE_prop_list CQHLBNCLKX4_cT_nonprop_list CQHLBNCLKX4_cT_prop_list


$index_number = $ARGV[0];
$file_list_name = "2";
open(FILE_LIST, "$file_list_name") || die "Can not open the file : $file_list_name \n";
@file_name = <FILE_LIST>;
close(FILE_LIST);


$search_num = 1;
@search_words = ();
# $search_words[0] = "t_en_trip_incap1";
# $search_words[1] = "t_en_trip_incap2";
# $search_words[2] = "nc_incap_en";
#$search_words[0] = "cin__din__hl_v0";
#$search_words[1] = "cin__din__hl_v1";
#$search_words[2] = "cin__din__hl_q";
$search_words[0] = "nc_intg_i_din";


%search_result;


open(OUTPUT, ">CQHFD2MEQX1_pTI.txt") || die "Can not open the file : hash.db \n";


foreach $file (@file_name) {
open(TEMFILE, ">temp.txt") || die "Can not open the file : temp.txt \n";
chomp($file);
s/alter#/alter# /g;
open(MT0_FILE, "$file") || die "Can not open the file : $file \n";
@mt0_file = <MT0_FILE>;
close(MT0_FILE);
#print OUTPUT "$file \n";



####### create a new file from "index"
$write_new_file=0;
foreach $line (@mt0_file) {
chomp($line);
@array01=split(" ",$line);
if ($array01[0] eq "index") { $write_new_file=1;}
if ($write_new_file==1) { print TEMFILE $line ;}
}
close(TEMFILE);
rename ("temp.txt","searching.txt");


open(SearchFile,"<searching.txt");
while(<SearchFile>){
chop $_;
@ary=split(" ",$_);
for ($i=0; $i<1000; $i++) {
for ($k=0; $k<$search_num; $k++) {
if ($ary[$i] eq $search_words[$k]){ $search_words_location[$k]=$i;
print "$search_words[$k] is located in $i \n"}
}
if ($ary[$i] eq "alter#") {$end_of_para=$i; $end_of_loop=1;
print "end_of_para is located in $i \n"}
#if ($end_of_loop==1) {last;}
}
}
close (SearchFile);



## K loop for the number of searching items
for ($k=0; $k<$search_num; $k++) {
for ($j=0; $j<=$index_number; $j++) {
if ($j==0){$target_number= $search_words_location[$k]}
unless ($j==0) {$target_number= $search_words_location[$k] + ($j*$end_of_para+$j);}
print "$ary[$target_number]"." ";
print OUTPUT "$ary[$target_number]". " ";
}
print "\n";
print OUTPUT "\n";
}}
close(OUTPUT);


 


沒有留言:

張貼留言

標籤