Sponsored Content
Top Forums Shell Programming and Scripting Extract multiple repeated data from a text file Post 302306822 by summer_cherry on Tuesday 14th of April 2009 12:02:09 AM
Old 04-14-2009
seems perl is a good choice to handle it.

Code:
$/="\n\n";
open $fh,"<","a.txt";
while(<$fh>){
	my $tmp=sprintf("%s.txt",$.);
	open my $fh1,">",$tmp;
	print $fh1 $_;
	close $fh1;
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to extract data from a text file

Hello All, Is there an easy way to extract data from a text file? The text file is actually a dump of a 2 page report with 6 columns and 122 lines. Example is Report Tile Type Product 1 Product 2 Product 3 Product 4... (1 Reply)
Discussion started by: negixx
1 Replies

2. Shell Programming and Scripting

Delete repeated word in text file

Hi expert, I am using C shell. And i trying to delete repeated word. Example file.txt: BLUE YELLOW RED VIOLET RED RED BLUE WHITE YELLOW BLACK and i wan store the output into a new file: BLUE (6 Replies)
Discussion started by: vincyoxy
6 Replies

3. UNIX for Dummies Questions & Answers

Help please, extract multiple lines from a text file

Hi all, I need to extract lines between the lines 'RD' and 'QA' from a text file (following). there are more that one of such pattern in the file and I need to extract all of them. however, the number of lines between them is varied in the file. Therefore, I can not just use 'grep -A' command.... (6 Replies)
Discussion started by: johnshembb
6 Replies

4. UNIX for Dummies Questions & Answers

AWK, extract data from multiple files

Hi, I'm using AWK to try to extract data from multiple files (*.txt). The script should look for a flag that occurs at a specific position in each file and it should return the data to the right of that flag. I should end up with one line for each file, each containing 3 columns:... (8 Replies)
Discussion started by: Liverpaul09
8 Replies

5. Shell Programming and Scripting

How to find repeated string in a text file

I have a text file where I need to find the string = ST*850* This string is repetaed several times in the file, so I need to know how many times it appears in the file, this is the text files: ISA*00* *00* *08*925485USNR *ZZ*IMSALADDERSP... (13 Replies)
Discussion started by: cucosss
13 Replies

6. Shell Programming and Scripting

regular expression with shell script to extract data out of a text file

hi i am trying to extract some specific data out of a text file using regular expressions with shell script that is using a multiline grep .. and the tool i am using is pcregrep so that i can get compatibility with perl's regular expressions for a sample data like this, i am trying to grab... (6 Replies)
Discussion started by: vemkiran
6 Replies

7. UNIX for Dummies Questions & Answers

Extract common data out of multiple files

I am trying to extract common list of Organisms from different files For example I took 3 files and showed expected result. In real I have more than 1000 files. I am aware about the useful use of awk and grep but unaware in depth so need guidance regarding it. I want to use awk/ grep/ cut/... (7 Replies)
Discussion started by: macmath
7 Replies

8. Shell Programming and Scripting

Extract data in tabular format from multiple files

Hi, I have directory with multiple files from which i need to extract portion of specif lines and insert it in a new file, the new file will contain a separate columns for each file data. Example: I need to extract Value_1 & Value_3 from all files and insert in output file as below: ... (2 Replies)
Discussion started by: belalr
2 Replies

9. Shell Programming and Scripting

awk used to extract data between text

Hello all, I have a file (filename.txt) with some data (in two columns X and Y) which looks like this: ########## 'Header1' 'Sub-header1' X Y xxxx.xx yyyy.yyy xxxx.xx yyyy.yyy .... ... 'Sub-header2' X Y xxxx.xx ... (7 Replies)
Discussion started by: jaldo0805
7 Replies

10. UNIX for Beginners Questions & Answers

Shell - Read a text file with two words and extract data

hi I made this simple script to extract data and pretty much is a list and would like to extract data of two words separated by commas and I would like to make a new text file that would list these extracted data into a list and each in a new line. Example that worked for me with text file... (5 Replies)
Discussion started by: dandaryll
5 Replies
IO::Async::Handle(3pm)					User Contributed Perl Documentation				    IO::Async::Handle(3pm)

NAME
"IO::Async::Handle" - event callbacks for a non-blocking file descriptor SYNOPSIS
This class is likely not to be used directly, because subclasses of it exist to handle more specific cases. Here is an example of how it would be used to watch a listening socket for new connections. In real code, it is likely that the "Loop->listen" method would be used instead. use IO::Socket::INET; use IO::Async::Handle; use IO::Async::Loop; my $loop = IO::Async::Loop->new; my $socket = IO::Socket::INET->new( LocalPort => 1234, Listen => 1 ); my $handle = IO::Async::Handle->new( handle => $socket, on_read_ready => sub { my $new_client = $socket->accept; ... }, ); $loop->add( $handle ); For most other uses with sockets, pipes or other filehandles that carry a byte stream, the IO::Async::Stream class is likely to be more suitable. For non-stream sockets, see IO::Async::Socket. DESCRIPTION
This subclass of IO::Async::Notifier allows non-blocking IO on filehandles. It provides event handlers for when the filehandle is read- or write-ready. EVENTS
The following events are invoked, either using subclass methods or CODE references in parameters: on_read_ready Invoked when the read handle becomes ready for reading. on_write_ready Invoked when the write handle becomes ready for writing. on_closed Optional. Invoked when the handle becomes closed. This handler is invoked before the filehandles are closed and the Handle removed from its containing Loop. The "loop" will still return the containing Loop object. PARAMETERS
The following named parameters may be passed to "new" or "configure": read_handle => IO write_handle => IO The reading and writing IO handles. Each must implement the "fileno" method. Primarily used for passing "STDIN" / "STDOUT"; see the SYNOPSIS section of "IO::Async::Stream" for an example. handle => IO The IO handle for both reading and writing; instead of passing each separately as above. Must implement "fileno" method in way that "IO::Handle" does. on_read_ready => CODE on_write_ready => CODE on_closed => CODE CODE references for event handlers. want_readready => BOOL want_writeready => BOOL If present, enable or disable read- or write-ready notification as per the "want_readready" and "want_writeready" methods. It is required that a matching "on_read_ready" or "on_write_ready" are available for any handle that is provided; either passed as a callback CODE reference or as an overridden the method. I.e. if only a "read_handle" is given, then "on_write_ready" can be absent. If "handle" is used as a shortcut, then both read and write-ready callbacks or methods are required. If no IO handles are provided at construction time, the object is still created but will not yet be fully-functional as a Handle. IO handles can be assigned later using the "set_handle" or "set_handles" methods, or by "configure". This may be useful when constructing an object to represent a network connection, before the connect(2) has actually been performed yet. METHODS
$handle->set_handles( %params ) Sets new reading or writing filehandles. Equivalent to calling the "configure" method with the same parameters. $handle->set_handle( $fh ) Shortcut for $handle->configure( handle => $fh ) $handle->close This method calls "close" on the underlying IO handles. This method will then remove the handle from its containing loop. $handle->close_read $handle->close_write Closes the underlying read or write handle, and deconfigures it from the object. Neither of these methods will invoke the "on_closed" event, nor remove the object from the Loop if there is still one open handle in the object. Only when both handles are closed, will "on_closed" be fired, and the object removed. $handle = $handle->read_handle $handle = $handle->write_handle These accessors return the underlying IO handles. $fileno = $handle->read_fileno $fileno = $handle->write_fileno These accessors return the file descriptor numbers of the underlying IO handles. $value = $handle->want_readready $oldvalue = $handle->want_readready( $newvalue ) $value = $handle->want_writeready $oldvalue = $handle->want_writeready( $newvalue ) These are the accessor for the "want_readready" and "want_writeready" properties, which define whether the object is interested in knowing about read- or write-readiness on the underlying file handle. SEE ALSO
o IO::Handle - Supply object methods for I/O handles AUTHOR
Paul Evans <leonerd@leonerd.org.uk> perl v5.14.2 2012-10-24 IO::Async::Handle(3pm)
All times are GMT -4. The time now is 01:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy