Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Copying Text between two unique text patterns Post 302119185 by ennstate on Monday 28th of May 2007 03:03:36 PM
Old 05-28-2007
Hi Simon,
Though there could some other smarter solution,I have used the following approach to solve this problem.

Assuming we have the contents of the file /tmp/MyNewArticleFile.rtf as ,

cat /tmp/MyNewArticleFile.rtf
HTML Code:
Times of India
Edition-1
Date:27 th May

Document 1 of 20

All blah blah goes here
Ad Page
Blah

================================

Document 2 of 20

All blah blah goes here
Ad Page
Blah

================================

Document 3 of 20

All blah blah goes here
Ad Page
Blah

================================
Document 4 of 20

All blah blah goes here
Ad Page
Blah

================================
End of the Edition
Thanks
Editor
I have written the following script that process the above file to generate the output.
Here the assumption is the Document has 20 Pages.
Code:
#!/bin/ksh
let page=1
while [[ page -le 20 ]] ; do
sed -n /Document\ $page/,/==========*/p /tmp/MyNewArticleFile.rtf > /tmp/ArticleSplitPage-$page
((page=page+1))
done

Upon execution of the above script i get 20 pages spilt according to the Document no.

cat /tmp/ArticleSpiltPage-1
HTML Code:
Document 1 of 20

All blah blah goes here
Ad Page
Blah

================================
Thanks,
Nagarajan Ganesan.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extracting unique lines from text file

I have a file with 14million lines and I would like to extract all the unique lines from the file into another text file. For example: Contents of file1 happy sad smile happy funny sad I want to run a command against file one that only returns the unique lines (ie 1 line for happy... (3 Replies)
Discussion started by: soliberus
3 Replies

2. Shell Programming and Scripting

Extracting Text Between Two Unique Lines

Hi all! Im trying to extract a portion of text from a file and put it into a new file. I need all the lines between <Placement> and </Placement> including the Placemark lines themselves. Is there a way to extract all instances of these and not just the first one found? I've tried using sed and... (4 Replies)
Discussion started by: Grizzly
4 Replies

3. Shell Programming and Scripting

Extracting several lines of text after a unique string

I'm attempting to write a script to identify users who have sudo access on a server. I only want to extract the ID's of the sudo users after a unique line of text. The list of sudo users goes to the EOF so I only need the script to start after the unique line of text. I already have a script to... (1 Reply)
Discussion started by: bouncer
1 Replies

4. UNIX for Advanced & Expert Users

Vi copying text

Is there a trick for copying from something like a powerpoint into vi? Every time I try to copy text from something like a powerpoint to vi my spacing gets messed up. I think it has something to do with my .vimrc file. When I renamed it was able to copy it in just fine so can someone please... (2 Replies)
Discussion started by: cokedude
2 Replies

5. UNIX for Dummies Questions & Answers

Copying text from Windows to AIX - missing text?

Hi All, I'm hoping this is an easy question, but I'm having a weird problem trying to simply copy and paste text from MS Windows (XP) Notepad and then pasting into vi or vim in AIX. When I type "oslevel" I get "5.3.0.0". The problem is that once the text is pasted, there are sections of text... (2 Replies)
Discussion started by: PlainInverted
2 Replies

6. Shell Programming and Scripting

Replacing text between two patterns

I would like to replace ], with ]]], between /* SECTION2-BEGIN */ and /* SECTION2-END */ in my file. My file contains the following information: /* SECTION1-BEGIN */ , /* SECTION1-END */ /* SECTION2-BEGIN */ , /* SECTION2-END */ /*... (5 Replies)
Discussion started by: azdps
5 Replies

7. Shell Programming and Scripting

Need to extract text repetitively between two patterns

Hi All, I want to extract the text between some pattern which occurs repeatedly in a file. For example my input is like, /home/..... ..........java:25: cannot find symbol ............ /home/...... /home/....... I want to display... (2 Replies)
Discussion started by: Vignesh58
2 Replies

8. Shell Programming and Scripting

Find patterns and filter the text

I need to filter the text in between two patterns and output that to a different file. Please help me how to do it. Ex: ............. <some random text> ............. Pattern_1 <Few lines that need to be output to different file> Pattern_2 ................ ............... <more text in... (4 Replies)
Discussion started by: metturr
4 Replies

9. Shell Programming and Scripting

Command for non-unique text

awk -F "" '/<TestName>|<testname>|<Offerer>|<offerer>|<Line1>|<line1>|<City>|<city>|<State>|<state>/ {print $2, $3}' OFS='\t' UBE3A.xml > UBE3A.txt Is it possible to use the code above to search for a pattern that is non-unique? For example, if I wanted to capture the<MethodList>|<string>... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. Shell Programming and Scripting

awk to print unique text in field

I am trying to use awk to print the unique entries in $2 So in the example below there are 3 lines but 2 of the lines match in $2 so only one is used in the output. File.txt chr17:29667512-29667673 NF1:exon.1;NF1:exon.2;NF1:exon.38;NF1:exon.4;NF1:exon.46;NF1:exon.47 703.807... (5 Replies)
Discussion started by: cmccabe
5 Replies
Template::Document(3pm) 				User Contributed Perl Documentation				   Template::Document(3pm)

NAME
Template::Document - Compiled template document object SYNOPSIS
use Template::Document; $doc = Template::Document->new({ BLOCK => sub { # some perl code; return $some_text }, DEFBLOCKS => { header => sub { # more perl code; return $some_text }, footer => sub { # blah blah blah; return $some_text }, }, METADATA => { author => 'Andy Wardley', version => 3.14, } }) || die $Template::Document::ERROR; print $doc->process($context); DESCRIPTION
This module defines an object class whose instances represent compiled template documents. The Template::Parser module creates a "Template::Document" instance to encapsulate a template as it is compiled into Perl code. The constructor method, new(), expects a reference to a hash array containing the "BLOCK", "DEFBLOCKS" and "METADATA" items. The "BLOCK" item should contain a reference to a Perl subroutine or a textual representation of Perl code, as generated by the Template::Parser module. This is then evaluated into a subroutine reference using "eval()". The "DEFLOCKS" item should reference a hash array containing further named "BLOCK"s which may be defined in the template. The keys represent "BLOCK" names and the values should be subroutine references or text strings of Perl code as per the main "BLOCK" item. The "METADATA" item should reference a hash array of metadata items relevant to the document. The process() method can then be called on the instantiated "Template::Document" object, passing a reference to a Template::Context object as the first parameter. This will install any locally defined blocks ("DEFBLOCKS") in the "BLOCKS" cache in the context (via a call to visit()) so that they may be subsequently resolved by the context. The main "BLOCK" subroutine is then executed, passing the context reference on as a parameter. The text returned from the template subroutine is then returned by the process() method, after calling the context leave() method to permit cleanup and de-registration of named "BLOCKS" previously installed. An "AUTOLOAD" method provides access to the "METADATA" items for the document. The Template::Service module installs a reference to the main "Template::Document" object in the stash as the "template" variable. This allows metadata items to be accessed from within templates, including "PRE_PROCESS" templates. header: <html> <head> <title>[% template.title %] </head> ... "Template::Document" objects are usually created by the Template::Parser but can be manually instantiated or sub-classed to provide custom template components. METHODS
new(\%config) Constructor method which accept a reference to a hash array containing the structure as shown in this example: $doc = Template::Document->new({ BLOCK => sub { # some perl code; return $some_text }, DEFBLOCKS => { header => sub { # more perl code; return $some_text }, footer => sub { # blah blah blah; return $some_text }, }, METADATA => { author => 'Andy Wardley', version => 3.14, } }) || die $Template::Document::ERROR; "BLOCK" and "DEFBLOCKS" items may be expressed as references to Perl subroutines or as text strings containing Perl subroutine definitions, as is generated by the Template::Parser module. These are evaluated into subroutine references using "eval()". Returns a new "Template::Document" object or "undef" on error. The error() class method can be called, or the $ERROR package variable inspected to retrieve the relevant error message. process($context) Main processing routine for the compiled template document. A reference to a Template::Context object should be passed as the first parameter. The method installs any locally defined blocks via a call to the context visit() method, processes its own template, (passing the context reference as a parameter) and then calls leave() in the context to allow cleanup. print $doc->process($context); Returns a text string representing the generated output for the template. Errors are thrown via "die()". block() Returns a reference to the main "BLOCK" subroutine. blocks() Returns a reference to the hash array of named "DEFBLOCKS" subroutines. variables() Returns a reference to a hash of variables used in the template. This requires the TRACE_VARS option to be enabled. AUTOLOAD An autoload method returns "METADATA" items. print $doc->author(); CLASS METHODS
These methods are used internally. as_perl($content) This method generate a Perl representation of the template. my $perl = Template::Document->as_perl({ BLOCK => $main_block, DEFBLOCKS => { foo => $foo_block, bar => $bar_block, }, METADATA => { name => 'my_template', } }); write_perl_file(\%config) This method is used to write compiled Perl templates to disk. If the "COMPILE_EXT" option (to indicate a file extension for saving compiled templates) then the Template::Parser module calls this subroutine before calling the new() constructor. At this stage, the parser has a representation of the template as text strings containing Perl code. We can write that to a file, enclosed in a small wrapper which will allow us to susequently "require()" the file and have Perl parse and compile it into a "Template::Document". Thus we have persistence of compiled templates. INTERNAL FUNCTIONS
catch_warnings() This is a simple handler used to catch any errors that arise when the compiled Perl template is first evaluated (that is, evaluated by Perl to create a template subroutine at compile, rather than the template being processed at runtime). is_utf8() This is mapped to "utf8::is_utf8" for versions of Perl that have it (> 5.008) or to "Encode::is_utf8" for Perl 5.008. Earlier versions of Perl are not supported. AUTHOR
Andy Wardley <abw@wardley.org> <http://wardley.org/> COPYRIGHT
Copyright (C) 1996-2012 Andy Wardley. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Template, Template::Parser perl v5.14.2 2012-01-25 Template::Document(3pm)
All times are GMT -4. The time now is 04:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy