Sponsored Content
Top Forums Shell Programming and Scripting Single line file editing command? Post 302181554 by in2nix4life on Thursday 3rd of April 2008 10:09:42 AM
Old 04-03-2008
Not sure what kind of editing you want to do, but for simple find and replace, sed with the -i switch can perform that function in place.

sed -i.orig -e 's/pattern1/pattern2/g'

The -i.orig will make the change in the file and make a copy of the original file with the .orig extension in case you need to revert to the original file.

Hope this helps steer you in the right direction.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

editing bash command line with vi

Is there a way using bash that I can edit a command line using vi. I.e. if I have a long command line and I want to edit it.....by typing vi and then having the command open in an editing window.... I beleive this can be done in k shell by pressing v....however can find out how this can be... (3 Replies)
Discussion started by: peter.herlihy
3 Replies

2. Shell Programming and Scripting

single line command

i need to search for a single pattern in three different logs....what would be the best one line script???? (4 Replies)
Discussion started by: roshanjain2
4 Replies

3. UNIX for Advanced & Expert Users

Can't Editing File in Single mode (using vi)

Dear All, Yesterday I'm change /etc/vfstab file ( disable 1 Device mounting) and now I can't login to multiuser mode just single user mode, and now I want enable again, but I can't using vi editor in single user mode How to edit this file? thereis default can't using vi editor in single mode?... (14 Replies)
Discussion started by: heru_90
14 Replies

4. Shell Programming and Scripting

Editing last line of a file

Hi All, Could you please help me out with this problem? I need to edit the last line of my file. Ex: The last line in my file will be say 000056000045 8 I need to subtract some number from the number 45 and replace the new number in its place. ... (1 Reply)
Discussion started by: Anitha Chandran
1 Replies

5. UNIX for Dummies Questions & Answers

single line command to delete a 6 months old file

i had this scenario where i need to delete a file that is 6 months old which is no longer needed. basically the filename is in the format of PCARDDAILYmmddyyyy.txt where the mm is the month, dd is the day, and yyyy is the year. e.g. PCARDDAILY05262009.txt PCARDDAILY05252009.txt ... (6 Replies)
Discussion started by: wtolentino
6 Replies

6. UNIX for Dummies Questions & Answers

ksh command line editing text being overwritten

hi. i'm using ksh with set -o vi. if i am far down in a directory and try to edit the command line (esc-k to retrieve previous command) the cursor is being positioned over to the left on top of the directory text making the text very difficult to read or work with. seems to be problem with long... (2 Replies)
Discussion started by: jeffa123
2 Replies

7. Shell Programming and Scripting

Editing the first line of file

I have a sample file as below :- RECORD_COUNT|2660|28606946.86|20110701122349694| adkad|wwsgesg|mkmk|FFFF|FAFAF|FFAF|FAFFFFA|5894858| I have to replace the second coulmn in the first row which is the count of no of lines in the file from a new variable . Also I have to delete the 3rd... (2 Replies)
Discussion started by: Sanjeev Yadav
2 Replies

8. Shell Programming and Scripting

editing single line in html file in perl script

Hi Folks, It is regarding the perl scripting. I have an html file(many files) which contains the below line in the body tag. <body> <P><STRONG><FONT face="comic sans ms,cursive,sans-serif"><EM>Hello</EM></FONT></STRONG></P> </body> Now I want to read that html file through perl... (3 Replies)
Discussion started by: giridhar276
3 Replies

9. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

10. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies
Class::Method::Modifiers(3pm)				User Contributed Perl Documentation			     Class::Method::Modifiers(3pm)

NAME
Class::Method::Modifiers - provides Moose-like method modifiers SYNOPSIS
package Child; use parent 'Parent'; use Class::Method::Modifiers; sub new_method { } before 'old_method' => sub { carp "old_method is deprecated, use new_method"; }; around 'other_method' => sub { my $orig = shift; my $ret = $orig->(@_); return $ret =~ /d/ ? $ret : lc $ret; }; after 'private', 'protected' => sub { debug "finished calling a dangerous method"; }; DESCRIPTION
Method modifiers are a convenient feature from the CLOS (Common Lisp Object System) world. In its most basic form, a method modifier is just a method that calls "$self->SUPER::foo(@_)". I for one have trouble remembering that exact invocation, so my classes seldom re-dispatch to their base classes. Very bad! "Class::Method::Modifiers" provides three modifiers: "before", "around", and "after". "before" and "after" are run just before and after the method they modify, but can not really affect that original method. "around" is run in place of the original method, with a hook to easily call that original method. See the "MODIFIERS" section for more details on how the particular modifiers work. One clear benefit of using "Class::Method::Modifiers" is that you can define multiple modifiers in a single namespace. These separate modifiers don't need to know about each other. This makes top-down design easy. Have a base class that provides the skeleton methods of each operation, and have plugins modify those methods to flesh out the specifics. Parent classes need not know about "Class::Method::Modifiers". This means you should be able to modify methods in any subclass. See Term::VT102::ZeroBased for an example of subclassing with CMM. In short, "Class::Method::Modifiers" solves the problem of making sure you call "$self->SUPER::foo(@_)", and provides a cleaner interface for it. As of version 1.00, "Class::Method::Modifiers" is faster in some cases than Moose. See "benchmark/method_modifiers.pl" in the Moose distribution. MODIFIERS
before method(s) => sub { ... } "before" is called before the method it is modifying. Its return value is totally ignored. It receives the same @_ as the the method it is modifying would have received. You can modify the @_ the original method will receive by changing $_[0] and friends (or by changing anything inside a reference). This is a feature! after method(s) => sub { ... } "after" is called after the method it is modifying. Its return value is totally ignored. It receives the same @_ as the the method it is modifying received, mostly. The original method can modify @_ (such as by changing $_[0] or references) and "after" will see the modified version. If you don't like this behavior, specify both a "before" and "after", and copy the @_ during "before" for "after" to use. around method(s) => sub { ... } "around" is called instead of the method it is modifying. The method you're overriding is passed in as the first argument (called $orig by convention). Watch out for contextual return values of $orig. You can use "around" to: Pass $orig a different @_ around 'method' => sub { my $orig = shift; my $self = shift; $orig->($self, reverse @_); }; Munge the return value of $orig around 'method' => sub { my $orig = shift; ucfirst $orig->(@_); }; Avoid calling $orig -- conditionally around 'method' => sub { my $orig = shift; return $orig->(@_) if time() % 2; return "no dice, captain"; }; install_modifier $package, $type, @names, sub { ... } "install_modifier" is like "before", "after", and "around" but it also lets you dynamically select the modifier type ('before', 'after', 'around') and package that the method modifiers are installed into. This expert-level function is exported only when you ask for it specifically, or for ":all". NOTES
All three normal modifiers; "before", "after", and "around"; are exported into your namespace by default. You may "use Class::Method::Modifiers ()" to avoid thrashing your namespace. I may steal more features from Moose, namely "super", "override", "inner", "augment", and whatever the Moose folks come up with next. Note that the syntax and semantics for these modifiers is directly borrowed from Moose (the implementations, however, are not). Class::Trigger shares a few similarities with "Class::Method::Modifiers", and they even have some overlap in purpose -- both can be used to implement highly pluggable applications. The difference is that Class::Trigger provides a mechanism for easily letting parent classes to invoke hooks defined by other code. "Class::Method::Modifiers" provides a way of overriding/augmenting methods safely, and the parent class need not know about it. CAVEATS
It is erroneous to modify a method that doesn't exist in your class's inheritance hierarchy. If this occurs, an exception will be thrown when the modifier is defined. It doesn't yet play well with "caller". There are some todo tests for this. Don't get your hopes up though! VERSION
This module was bumped to 1.00 following a complete reimplementation, to indicate breaking backwards compatibility. The "guard" modifier was removed, and the internals are completely different. The new version is a few times faster with half the code. It's now even faster than Moose. Any code that just used modifiers should not change in behavior, except to become more correct. And, of course, faster. :) SEE ALSO
Class::Method::Modifiers::Fast Moose, Class::Trigger, Class::MOP::Method::Wrapped, MRO::Compat, CLOS AUTHOR
Shawn M Moore, "sartak@gmail.com" ACKNOWLEDGEMENTS
Thanks to Stevan Little for Moose, I would never have known about method modifiers otherwise. Thanks to Matt Trout and Stevan Little for their advice. COPYRIGHT AND LICENSE
Copyright 2007-2009 Shawn M Moore. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-04-03 Class::Method::Modifiers(3pm)
All times are GMT -4. The time now is 12:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy