Sponsored Content
Top Forums Shell Programming and Scripting Copying/Extracting from line A to line B Post 302262255 by summer_cherry on Wednesday 26th of November 2008 09:03:10 PM
Old 11-26-2008
hope below perl give you some light

Code:
package UserFile;
sub new{
	shift;
	$file=shift;
	$data={};
	_open();
	return bless $data;
}
sub _open{
	open FH,"<$file";
}
sub _close{
	close FH;
}
# 1: exchange 2: overwrite 3: append/copy
sub pCnt{
	my($slef,$type,$l1,$l2)=(@_);
	my @arr=<FH>;
	if ($type==1) {$temp=$arr[$l1];$arr[$l1]=$arr[$l2];$arr[$l2]=$temp;} 
	if ($type==2) {$arr[$l2]=$arr[$l1];}
	if ($type==3) {for($i=$#arr+1;$i>$l2;$i--){$arr[$i]=$arr[$i-1];}$arr[$l2]=$arr[$l1];} 
	print "@arr";
	_close();
}
1

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

getting the line number by extracting a line

grep "KeyNotFoundException" weblogic.log After running this command the output is abcxyzexceptions.KeyNotFoundException: Person not found How to know ..what is the line number of the above string in the log file. (2 Replies)
Discussion started by: bishweshwar
2 Replies

2. Shell Programming and Scripting

extracting a line based on line number

i want to cut all the entries from the /etc/passwd file in which the uid is> 500 for this i was writing this ,m quiet new to all this.. scripting but on the 6th n 8th line ,, i hav to specify a line number .. to get the commnd working .. but i want to use variable i instead of that ,,... (2 Replies)
Discussion started by: narendra.pant
2 Replies

3. Shell Programming and Scripting

copying from line N1 to line N2 of a file in a series of files

Dear community, I'm quite a newbie with scripting, I have this problem: I have a file with many lines and I want to copy the lines from 1 to N to file.1, from N+1 to 2N to file.2, and so on up to the end of the file I have tried with something like this (N=43 in this example): awk '{for... (2 Replies)
Discussion started by: paolalup
2 Replies

4. Shell Programming and Scripting

Copying x words from end of line to specific location in same line

Hello all i know it is pretty hard one but you will manage it all after noticing and calculating i find a rhythm for the file i want to edit to copy the last 12 characters in line but the problem is to add after first 25 characters in same line in other way too copy the last 12 characters... (10 Replies)
Discussion started by: princesasa
10 Replies

5. Shell Programming and Scripting

Copying a line from one file to other using vi editor

Hi Guys, the command ":yy" copies the line but it can be pasted in the same file. How can it be done if I want to copy it in other file. (2 Replies)
Discussion started by: ajincoep
2 Replies

6. Shell Programming and Scripting

copying a line from a file using sed

Hi All, I need to copy a specific line from a file to another file. lets suppose the line number 13 of a file when I am writing the line number explicitly.. its working fine sed -n '13p' afile > anotherfile but, when inside a script, i am getting the line number value inside a variable... (4 Replies)
Discussion started by: gotamp
4 Replies

7. UNIX for Dummies Questions & Answers

Copying a command/line to clipboard

hi all, i am newbie to Unix scripting.. I am writing a script which will have a line of commands, which needs to be copied to clipboard. Any ideas welcome.. Usage:: I am using the script in this way, The script will have some lines (like below) export TERM=xterm; cd test_env; TMOUT=0 ... (1 Reply)
Discussion started by: gkarthik.gk
1 Replies

8. Shell Programming and Scripting

copying to the end of the line

Hi, I have a file as such 1 <text1><text2></ 2 <text3><text4></ 3 <text5><text6></ 4 <text7><text8></ I need is so the first bit of text in the line is at the end as its xml so 1 <text1><text2></text1> 2 <text3><text4></text3> 3 <text5><text6></text5> 4 ... (12 Replies)
Discussion started by: legolad
12 Replies

9. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

10. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies
Template::Plugin(3)					User Contributed Perl Documentation				       Template::Plugin(3)

NAME
Template::Plugin - Base class for Template Toolkit plugins SYNOPSIS
package MyOrg::Template::Plugin::MyPlugin; use base qw( Template::Plugin ); use Template::Plugin; use MyModule; sub new { my $class = shift; my $context = shift; bless { ... }, $class; } DESCRIPTION
A "plugin" for the Template Toolkit is simply a Perl module which exists in a known package location (e.g. "Template::Plugin::*") and conforms to a regular standard, allowing it to be loaded and used automatically. The "Template::Plugin" module defines a base class from which other plugin modules can be derived. A plugin does not have to be derived from Template::Plugin but should at least conform to its object-oriented interface. It is recommended that you create plugins in your own package namespace to avoid conflict with toolkit plugins. e.g. package MyOrg::Template::Plugin::FooBar; Use the PLUGIN_BASE option to specify the namespace that you use. e.g. use Template; my $template = Template->new({ PLUGIN_BASE => 'MyOrg::Template::Plugin', }); METHODS
The following methods form the basic interface between the Template Toolkit and plugin modules. load($context) This method is called by the Template Toolkit when the plugin module is first loaded. It is called as a package method and thus implicitly receives the package name as the first parameter. A reference to the Template::Context object loading the plugin is also passed. The default behaviour for the "load()" method is to simply return the class name. The calling context then uses this class name to call the "new()" package method. package MyPlugin; sub load { # called as MyPlugin->load($context) my ($class, $context) = @_; return $class; # returns 'MyPlugin' } new($context, @params) This method is called to instantiate a new plugin object for the "USE" directive. It is called as a package method against the class name returned by load(). A reference to the Template::Context object creating the plugin is passed, along with any additional parameters specified in the "USE" directive. sub new { # called as MyPlugin->new($context) my ($class, $context, @params) = @_; bless { _CONTEXT => $context, }, $class; # returns blessed MyPlugin object } error($error) This method, inherited from the Template::Base module, is used for reporting and returning errors. It can be called as a package method to set/return the $ERROR package variable, or as an object method to set/return the object "_ERROR" member. When called with an argument, it sets the relevant variable and returns "undef." When called without an argument, it returns the value of the variable. package MyPlugin; use base 'Template::Plugin'; sub new { my ($class, $context, $dsn) = @_; return $class->error('No data source specified') unless $dsn; bless { _DSN => $dsn, }, $class; } package main; my $something = MyPlugin->new() || die MyPlugin->error(), " "; $something->do_something() || die $something->error(), " "; DEEPER MAGIC
The Template::Context object that handles the loading and use of plugins calls the new() and error() methods against the package name returned by the load() method. In pseudo-code terms looks something like this: $class = MyPlugin->load($context); # returns 'MyPlugin' $object = $class->new($context, @params) # MyPlugin->new(...) || die $class->error(); # MyPlugin->error() The load() method may alterately return a blessed reference to an object instance. In this case, new() and error() are then called as object methods against that prototype instance. package YourPlugin; sub load { my ($class, $context) = @_; bless { _CONTEXT => $context, }, $class; } sub new { my ($self, $context, @params) = @_; return $self; } In this example, we have implemented a 'Singleton' plugin. One object gets created when load() is called and this simply returns itself for each call to new(). Another implementation might require individual objects to be created for every call to new(), but with each object sharing a reference to some other object to maintain cached data, database handles, etc. This pseudo-code example demonstrates the principle. package MyServer; sub load { my ($class, $context) = @_; bless { _CONTEXT => $context, _CACHE => { }, }, $class; } sub new { my ($self, $context, @params) = @_; MyClient->new($self, @params); } sub add_to_cache { ... } sub get_from_cache { ... } package MyClient; sub new { my ($class, $server, $blah) = @_; bless { _SERVER => $server, _BLAH => $blah, }, $class; } sub get { my $self = shift; $self->{ _SERVER }->get_from_cache(@_); } sub put { my $self = shift; $self->{ _SERVER }->add_to_cache(@_); } When the plugin is loaded, a "MyServer" instance is created. The new() method is called against this object which instantiates and returns a "MyClient" object, primed to communicate with the creating "MyServer". AUTHOR
Andy Wardley <abw@wardley.org> <http://wardley.org/> COPYRIGHT
Copyright (C) 1996-2007 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::Plugins, Template::Context perl v5.12.1 2008-11-13 Template::Plugin(3)
All times are GMT -4. The time now is 09:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy