Multiple Tag Search and Printing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple Tag Search and Printing
# 1  
Old 12-21-2011
Multiple Tag Search and Printing

Scenario:
The following text belongs to a .doc file
File: check1.asmFunction: MonksTag: NoTag: 001Tag: YesTag: 002File: check2.asmFunction: Perl MonksTag: YesTag: 003Tag: NoTag: 004File: check3.asmFunction: ExpertsTag: NoTag: 005Tag: NoTag: 006Function: Perl ExpertsTag: NoTag: 007Tag: YesTag: 008

I have to extract the tag which have been tagged as Yes and the corresponding function and file name to an excel sheet..
The output have to be like this:
Tags Function File002 Monks check1.asm003 Perl Monks check2.asm008 Perl Experts check3.asm

I have written the following snippet for extracting the tag which is categorized as Yes :
use strict; use warnings;use Win32::OLE;use Win32::OLE qw(in with);use Win32::OLE::Variant;use Win32::OLE::Const 'Microsoft Excel';use Win32::OLE::Const 'Microsoft Word'; use Cwd;use File::Find;use Win32::OLE;use Win32::OLE::Enum;$Win32::OLE::Warn = 3; # die on errors.+..my $out_file = 'check.xls';open my $out_fh, '>', $out_file or die "Could not open file $out_file:+$!";my $print_next = 0; #Globalsour $Word;our $reviewchklists;my @scriptfiles;@scriptfiles=glob('*.doc');foreach my $file (@scriptfiles){ my $var; my $filename = "D\:\\"; $var = $filename."$file"; print $var ; my $document = Win32::OLE -> GetObject("$var"); print "Extracting Text ...\n"; my @array; my $paragraphs = $document->Paragraphs(); my $enumerate = new Win32::OLE::Enum($paragraphs); while(my $paragraph = $enumerate->Next()) { my $text = $paragraph->{Range}->{Text}; $text =~ s/[\n\r\t]//g; $text =~ s/\x0B/\n/g; $text =~ s/\x07//g; chomp $text; my $Data .= $text; @array=split(/\.$/,$Data); foreach my $line( @array) { if ($print_next) { print $out_fh $line."\n" ; # we add a "\n" ; #No n+eed to chomp - we print the "\n" local $\ = "<br>\n"; local $/="\n\n"; } $print_next = ($line =~ /^Tag\sYes/); } } } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The above snippet is printing the output as follows:
ID : 002ID : 003ID : 008

I dont want the ID to be printed and how to extract the corresponding function and file name?
# 2  
Old 12-21-2011
Very confusing

1) Are you doing this in Windows, with DOS scripting?
2) Please wrap samples, input/output, scripts with CodeTags
3) Is the input file one long run-on like your example? You have
Code:
Tag: 002File: check2.asm

Are there spaces, return, etc... between fields?
4) Describe the rules on your Tag
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Display multiple words into a single td tag

awk 'BEGIN{print "<table>"} {print "<tr>"; for ( i=1;i<NF;i++) print " <td>" $I "</td>"; print "</tr>"} END{print " </table>"}' <file name > (6 Replies)
Discussion started by: Himanshu1
6 Replies

2. Shell Programming and Scripting

sed search and replace after xml tag

Hi All, I'm new to sed. In following XML file <interface type='direct'> <mac address='52:54:00:86:ce:f6'/> <source dev='eno1' mode='bridge'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> ... (8 Replies)
Discussion started by: varunrapelly
8 Replies

3. Shell Programming and Scripting

Search for a tag and display a message if not found.

Hi All, I am working with a XML file. Below is part for the file. <Emp:Profile> <Emp:Description>Admin</Emp:Description> <Emp:Id>12347</Emp:Id> </Emp:Profile> <Emp:Profile> ... (7 Replies)
Discussion started by: Girish19
7 Replies

4. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

5. Shell Programming and Scripting

Search for a html tag and print the entire tag

I want to print from <fruits> to </fruits> tag which have <fruit> as mango. Also i want both <fruits> and </fruits> in output. Please help eg. <fruits> <fruit id="111">mango<fruit> . another 20 lines . </fruits> (3 Replies)
Discussion started by: Ashik409
3 Replies

6. Shell Programming and Scripting

Need an efficient way to search for a tag in an xml file having millions of rows

Hi, I have an XML file with around 1 billion rows in it and i am trying to find the number of times a particular tag occurs in it. The solution i am using works but takes a lot of time (~1 hr) .Please help me with an efficient way to do this. Lets say the input file is <Root> ... (13 Replies)
Discussion started by: Sheel
13 Replies

7. Shell Programming and Scripting

search pattern and mark/tag

Hi All, I have to search for patterns from a pattern file in a file and mark the matching lines. Input File: Student1 60 30 Student2 71 91 Student3 88 98 Pattern file: Student1 Fail Student2 Pass Student2 Pass Desired output: Student1 60 30 Fail Student2 71 91 Pass (5 Replies)
Discussion started by: saint2006
5 Replies

8. Shell Programming and Scripting

Search and filter by TAG

Hello all, searching on a text file (log file) is quite simple: grep -i texttosearch filename | grep somethingWhat I'm trying to do is filter the result by TAG and remove the double entries. Like if the log file contains the following text (fields are separated by commas): ... (18 Replies)
Discussion started by: Lord Spectre
18 Replies

9. Shell Programming and Scripting

Search for particular tag and arrange as coordinates

Hi I have a file whose sample contents are shown here, 1.2.3.4->2.4.2.4 a(10) b(20) c(30) 1.2.3.4->2.9.2.4 a(10) c(20) 2.3.4.3->3.6.3.2 b(40) d(50) c(20) 2.3.4.3->3.9.0.2 a(40) e(50) c(20) 1.2.3.4->3.4.2.4 a(10) c(30) 6.2.3.4->2.4.2.5 c(10) . . . . Here I need to search... (5 Replies)
Discussion started by: AKD
5 Replies

10. Shell Programming and Scripting

getting multiple xml tag

sorry for the trouble...... i have this file that contains the following: 00:00:21 Queue key, Queue Name= 00:00:21 Sending Message :<EXGC-EXGU xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <trans_id>EXGC</trans_id> <sys_prefix>GSYS</sys_prefix> ... (3 Replies)
Discussion started by: forevercalz
3 Replies
Login or Register to Ask a Question