Sponsored Content
Top Forums Shell Programming and Scripting Pattern search and save it as .txt file with some name.. Post 302539851 by michaelrozar17 on Tuesday 19th of July 2011 02:42:39 AM
Old 07-19-2011
Please try to state your problem/requirement in a single post. Adding new requirement to each post may not comply with the subject line.
Code:
awk '/A123|O23/{print $0 >substr($0,0,4)".txt"}' test.txt

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search file for pattern and grab some lines before pattern

I want to search a file for a string and then if the string is found I need the line that the string is on - but also the previous two lines from the file (that the pattern will not be found in) This is on solaris Can you help? (2 Replies)
Discussion started by: frustrated1
2 Replies

2. Shell Programming and Scripting

replace character in a string pattern and save the change in same file

I am facing one problem, can any one please suggest me the command for the same in unix. I am using Ksh. I have a large file with the data that looks like below. "ROTO2-2007f","_US01","9/15/2007","9/21/2007",346492,"NICK, LCD WATCH"97,1,"NAPOLITJ ","BERGER,M Z & CO INC",0.01, ... (2 Replies)
Discussion started by: mihir0011
2 Replies

3. Shell Programming and Scripting

How search,edit and save the file

Hi All, I want to edit a file using shell script..For ex...a file called /etc/passwd..here I am searching for "ftp" if it is there just change it to "tftp" without using any temporary file. (3 Replies)
Discussion started by: Vichu
3 Replies

4. UNIX for Dummies Questions & Answers

Save Excel file as .txt in UNIX format

I have some files created in Excel that have to be saved as .txt files in order to load them into our accounting system. I can save the files as .txt files through Excel, but I then have to open them in TextPad and do a save as to change the Format from PC to UNIX. Is there a way to skip this step... (2 Replies)
Discussion started by: jroyalty
2 Replies

5. Shell Programming and Scripting

"Time" command and save result in a file.txt

Hi, I'am using "time" to check execution time of some script. Is there any possibility to save time command result into a file ? (2 Replies)
Discussion started by: Physix
2 Replies

6. Shell Programming and Scripting

Want to read data from a file name.txt and search it in another file and then matching...

Hi Frnds... I have an input file name.txt and another file named as source.. name.txt is having only one column and source is having around 25 columns...i need to read from name.txt line by line and search it in source file and then save the result in results file.. I have a rough idea about the... (15 Replies)
Discussion started by: ektubbe
15 Replies

7. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

8. Shell Programming and Scripting

Get the input from user and save it as .txt file

Hi friends, I am pretty new to shell scripting, please help me in this Scenario. for example, If I have one file called input.txt once I run the script, 1.It has to delete the old input.txt and create the new input.txt (if old input.txt is not there, no offence, just it has to create a... (2 Replies)
Discussion started by: Padmanabhan
2 Replies

9. Shell Programming and Scripting

How to use sed to search a particular pattern in a file backward after a pattern is matched.?

Hi, I have two files file1.txt and file2.txt. Please see the attachments. In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
Discussion started by: saurabh kumar
9 Replies

10. Shell Programming and Scripting

Save files in directory as txt

wget -x -i link.txt The above downloads and create unique entries for the 97 links in the text file. However, each new file is saved as CM080 with a FILE extention. Is there a way to convert each file in that directory to a .txt? The 97 files are in... (12 Replies)
Discussion started by: cmccabe
12 Replies
Sub::WrapPackages(3pm)					User Contributed Perl Documentation				    Sub::WrapPackages(3pm)

NAME
Sub::WrapPackages - add pre- and post-execution wrappers around all the subroutines in packages or around individual subs SYNOPSIS
use Sub::WrapPackages packages => [qw(Foo Bar Baz::*)], # wrap all subs in Foo and Bar # and any Baz::* packages subs => [qw(Barf::a, Barf::b)], # wrap these two subs as well wrap_inherited => 1, # and wrap any methods # inherited by Foo, Bar, or # Baz::* pre => sub { print "called $_[0] with params ". join(', ', @_[1..$#_])." "; }, post => sub { print "$_[0] returned $_[1] "; }; COMPATIBILITY
While this module does broadly the same job as the 1.x versions did, the interface may have changed incompatibly. Sorry. Hopefully it'll be more maintainable and slightly less crazily magical. Also, caller() should now work properly, ignoring wrappings. DESCRIPTION
This module installs pre- and post- execution subroutines for the subroutines or packages you specify. The pre-execution subroutine is passed the wrapped subroutine's name and all its arguments. The post-execution subroutine is passed the wrapped sub's name and its results. The return values from the pre- and post- subs are ignored, and they are called in the same context (void, scalar or list) as the calling code asked for. Normal usage is to pass a bunch of parameters when the module is used. However, you can also call Sub::WrapPackages::wrapsubs with the same parameters. PARAMETERS
Either pass parameters on loading the module, as above, or pass them to ... the wrapsubs subroutine the subs arrayref In the synopsis above, you will see two named parameters, "subs" and "packages". Any subroutine mentioned in "subs" will be wrapped. Any subroutines mentioned in 'subs' must already exist - ie their modules must be loaded - at the time you try to wrap them. the packages arrayref Any package mentioned here will have all its subroutines wrapped, including any that it imports at load-time. Packages can be loaded in any order - they don't have to already be loaded for Sub::WrapPackages to work its magic. You can specify wildcard packages. Anything ending in ::* is assumed to be such. For example, if you specify Orchard::Tree::*, then that matches Orchard::Tree, Orchard::Tree::Pear, Orchard::Apple::KingstonBlack etc, but not - of course - Pine::Tree or My::Orchard::Tree. Note, however, that if a module exports a subroutine at load-time using "import" then that sub will be wrapped in the exporting module but not in the importing module. This is because import() runs before we get a chance to fiddle with things. Sorry. Deferred wrapping of subs in packages that aren't yet loaded works via a subroutine inserted in @INC. This means that if you mess around with @INC, eg by inserting a directoy at the beginning of the path, the magic might not get a chance to run. If you "use lib" to mess with @INC though, it should work, as I've over-ridden lib's import() method. That said, code this funky has no right to work. Use with caution! wrap_inherited In conjunction with the "packages" arrayref, this wraps all calls to inherited methods made through those packages. If you call those methods directly in the superclass then they are not affected - unless they're wrapped in the superclass of course. pre and post References to the subroutines you want to use as wrappers. BUGS
AUTOLOAD and DESTROY are not treated as being special. I'm not sure whether they should be or not. If you use wrap_inherited but classes change their inheritance tree at run-time, then very bad things will happen. VERY BAD THINGS. So don't do that. You shouldn't be doing that anyway. Mind you, you shouldn't be doing the things that this module does either. BAD PROGRAMMER, NO BIKKIT! If you find any other lurking horrors, please report them using <https://rt.cpan.org/Public/Dist/Display.html?Name=Sub-WrapPackages>. FEEDBACK
I like to know who's using my code. All comments, including constructive criticism, are welcome. Please email me. SOURCE CODE REPOSITORY
<http://www.cantrell.org.uk/cgit/cgit.cgi/perlmodules/> COPYRIGHT and LICENCE Copyright 2003-2009 David Cantrell <david@cantrell.org.uk> This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. THANKS TO
Thanks to Tom Hukins for sending in a test case for the situation when a class and a subclass are both defined in the same file, and for prompting me to support inherited methods; to Dagfinn Ilmari Mannsaker for help with the craziness for fiddling with modules that haven't yet been loaded; to Lee Johnson for reporting a bug caused by perl 5.10's constant.pm being Far Too Clever, and providing a patch and test; to Adam Trickett who thought this was a jolly good idea; and to Ed Summers, whose code for figgering out what functions a package contains I borrowed out of Acme::Voodoo. perl v5.10.1 2010-03-06 Sub::WrapPackages(3pm)
All times are GMT -4. The time now is 09:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy