I have modified the program and now I am able to get the excel data Into a text file to be used as keywords. I want these keywords to be searched from no of files (main_log here) but not able to get the output like I want . My Input Data
8077 8116 D type hexa usim = 1, isim = 1 8077 8116 D type hexa usim = 1, isim = 1 pcscf_v4 : num = 2, protocol_type = 0x21, port_num = 0, addr = 10.56.5 +.85 8088 1223 D temp sim_invalid = 0 8099 1223 XX is_ems_support = 1 #88 8099 1224 XX pdn_act_ind->pcscf_discovery_flag = 1 ind->signaling_flag = 1 some text here plmn = 405872 DefaultStatusBarPlmnPlugin: into updateCarrierLabel ipv6 = 36.5.2.4.25.143.200.141.0.0.0.0.32.20.232.161 get_ipv6_prefix,temp ipv4 = 10.167.185.101 _send_ipv4_notify info.is_ems_support = 1 act_ind->emergency_indication = 1 access_rat_type = 0 transaction_id = 2, rat_type = 0

Variables to read from Excel sheet :

isim = usim = sim_invalid = pcscf_discovery_flag signaling_flag ran_type emergency_ind rat pcscf_v4 pcscf_v6 plmn is_ems_support ipv4 ipv6

#!/usr/bin/env perl use strict; use warnings; my $ex = ''; my $book = ''; my $sheet = ''; my $data = ''; my $my_data = 0; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; # use existing instance if Excel is already running eval {$ex = Win32::OLE->GetActiveObject('Excel.Application')}; die "Excel not installed" if $@; unless (defined $ex) { $ex = Win32::OLE->new('Excel.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Excel"; } $book = $ex->Workbooks->Open("E:\\Automation Related\\Perl Scripts - A +LL\\IMS_debugging\\Excel\\UE_NW_Parameters.xlsx"); $sheet = $book->Worksheets(1); $data = $sheet -> Range("A1:B2873") -> {Value}; # Opening the Output file for exporting the Excel data Into Text File open(FILE, ">excel_data.txt"); foreach my $cell_ref (@$data) { foreach my $my_data (@$cell_ref){ print FILE ($my_data); } print FILE "\n"; } close FILE; # Opening excel data File here open( my $kw, '<', 'excel_data.txt') or die $!; my @keywords = <$kw>; chomp(@keywords); # remove newlines at the end of keywords #get list of files in current directory my @files = <main_log*>; # loop over each file to search keywords in foreach my $file (@files) { open(my $fh, '<', $file) or die $!; my @content = <$fh>; close($fh); my $l = 0; my $outfile = 'excel_match'.$file.'.txt'; print "Check the output generated In file $outfile\n"; open my $fh_out, '>', $outfile or die "$!"; foreach my $kw (@keywords) { my $search = quotemeta($kw); # otherwise keyword is used as re +gex, not literally foreach (@content) { # go through every line for this keyword $l++; if (/\Q$search/) { print $fh_out "%s in file %s, line %d:%s'.$/, +$kw, $file, $l, $_"; last; } } } }

My input data to search from: 8077 8116 D type hexa usim = 1, isim = 1 8077 8116 D type hexa usim = 1, isim = 1 pcscf_v4 : num = 2, protocol_type = 0x21, port_num = 0, addr = 10.56.5.85 8088 1223 D temp sim_invalid = 0 8099 1223 XX is_ems_support = 1 #88 8099 1224 XX pdn_act_ind->pcscf_discovery_flag = 1 ind->signaling_flag = 1 some text here plmn = 405872 DefaultStatusBarPlmnPlugin: into updateCarrierLabel ipv6 = 36.5.2.4.25.143.200.141.0.0.0.0.32.20.232.161 get_ipv6_prefix,temp ipv4 = 10.167.185.101 _send_ipv4_notify info.is_ems_support = 1 act_ind->emergency_indication = 1 access_rat_type = 0 transaction_id = 2, rat_type = 0

My output should be like these for above data Into excel format isim = 1 usim = 1 sim_invalid = 0 pcscf_discovery_flag 1 signaling_flag 1 ran_type 0 emergency_ind 1 rat pcscf_v4 10.56.5.85 pcscf_v6 plmn 405872 is_ems_support 1 ipv4 10.167.185.101 ipv6 36.5.2.4.25.143.200.141.0.0.0.0.32.20.232.161

Issue - I am not able to get the corresponding lines searched matching keywords so I can pull out the variables value from these lines and put back into excel corresponding to these keywords e.g. x =5 (x is variable and 5 is the value to be picked from a line containing x) Can you please help ?

In reply to Re^7: How to read the value of a variable (read from a Excel file converted Into text file) and put then back into Excel column by rockyurock
in thread How to read the value of a variable (read from a Excel file converted Into text file) and put then back into Excel column by rockyurock

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.