Sponsored Content
Top Forums Shell Programming and Scripting Need to search a particular String form a file a write to another file using perl script Post 302855725 by Raysf on Friday 20th of September 2013 03:39:34 PM
Old 09-20-2013
Need to search a particular String form a file a write to another file using perl script

I have file which contains a huge amount of data. I need to search the pattern Message id. When that pattern is matched I need to get abcdeff0-1g6g-91g3-1z2z-2mm605m90000 to another file.
Kindly provide your input.

File is like below

Code:
Jan 11 04:05:10 linux100 |NOTICE |NET|NETDPCclient|thread:1|pid:[1234]: Message id, step 4 (abcdeff0-1g6g-91g3-1z2z-2mm605m90000)

Itried like this but its not working.

Code:
$Log="msg.log";
$OVOMSGIDFILE ="file.log";
 
open(LIST1, "<$Log") or die "Could not open chr1_22.txt: $!";
open(OUTPUT, "+>FILE") or die "Could not open chr1_23.txt: $!" ;
foreach my $line1 (<LIST1>)
{
chomp($line1);
# $line =~ m/'$1 if /Message id.+?(\w+-\w+-\w+-\w+-\w+)/'/);
'say $1 if /Message id.+?\((.+?)\)/' > OUTPUT;


Last edited by Scrutinizer; 09-20-2013 at 05:08 PM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to search a date format from a file an replace with a string in PERL

I am very new to Perl. I am struggling so hard to search a date (such as 10/09/2009, 10-09-2009) from a text file and replace with a string (say DATE) using Perl. Please help me out. Thanks in advance. Regds Doren (4 Replies)
Discussion started by: my_Perl
4 Replies

2. Shell Programming and Scripting

Extract string from a file & write to a new file (Perl)

Hi, This is the first time playing around with perl and need some help. Assuming if i have a line of text that looks like this: Date/Time=Nov 18 17:12:11;Device Name=192.168.1.1;Device IP=192.168.1.1;Device Class=IDS;Source IP=155.212.212.111;Source Name=UNKNOWN;Source Port=1679... (3 Replies)
Discussion started by: LuckyGuy
3 Replies

3. Shell Programming and Scripting

write shell script to search file in folder

hi .. i have a problem how to search file with date and version number(ms_2.0_dd/mm/yy_24)in folder.Here 24 is version number and compare the this file to other file which is in another folder and if does not match then copy this file to respective folder.Also copy different files in different... (1 Reply)
Discussion started by: shubhig15
1 Replies

4. Shell Programming and Scripting

search 3 file and write to 4th file (a bit complex)

hi buddies; rollbackip.txt:10.14.3.65 2 10.14.3.65 3 ... lookup.txt: ... 10.14.3.65 2 10.14.5.55 1 55 10.14.6.66 1 66 10.14.3.65 3 10.14.7.77 3 77 10.14.8.88 2 88 10.14.9.99 4 99 ... ip-port.txt ... port111 3 10.14.5.55 57 port111 2 10.14.5.55 51 port111 1 10.14.5.55 59 ->... (7 Replies)
Discussion started by: gc_sw
7 Replies

5. Programming

help need in the perl script that create one xml file form multiple files.

Hi every one, Please excuse me if any grammatical mistakes is there. I have multiple xml files in one directory, I need to create multiple XML files into one XML file.example files like this</p> file1:bvr.xml ... (0 Replies)
Discussion started by: veerubiji
0 Replies

6. Shell Programming and Scripting

perl- read search and replace string from the file

Dear all, I have a number of files and each file has two sections separated by a blank line. At the top section, I have lines which describes the values of the alphabetical characters, # s #; 0.123 # p #; 12.3 # d #; -2.33 # f #; 5.68 <blank line> sssssss spfdffff sdfffffff Now I... (4 Replies)
Discussion started by: sasharma
4 Replies

7. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

8. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

9. Shell Programming and Scripting

Shell script to search all files for every string in another file

Hello All I have a pattern.txt file in source directory ((/project/source/) in linux server and data looks like: 123abc17 234cdf19 235ifg20 I have multiple log files in log directory (/project/log/) in linux server and data for one log file looks like: <?xml version="1.0" processid... (11 Replies)
Discussion started by: pred55
11 Replies

10. Shell Programming and Scripting

How to Search a string in a file in shell script?

I have a text file which is generated when the batch job is run. This batch may take few mins to run. When completed, the last line of the text file would be process completed. I need a shell script which will wait for this file till the process completed is printed in it, once found, it would move... (2 Replies)
Discussion started by: Lalat
2 Replies
Log::Message::Handlers(3pm)				 Perl Programmers Reference Guide			       Log::Message::Handlers(3pm)

NAME
Log::Message::Handlers - Message handlers for Log::Message SYNOPSIS
# Implicitly used by Log::Message to serve as handlers for # Log::Message::Item objects # Create your own file with a package called # Log::Message::Handlers to add to the existing ones, or to even # overwrite them $item->carp; $item->trace; DESCRIPTION
Log::Message::Handlers provides handlers for Log::Message::Item objects. The handler corresponding to the level (see Log::Message::Item manpage for an explanation about levels) will be called automatically upon storing the error. Handlers may also explicitly be called on an Log::Message::Item object if one so desires (see the Log::Message manpage on how to retrieve the Item objects). Default Handlers log Will simply log the error on the stack, and do nothing special carp Will carp (see the Carp manpage) with the error, and add the timestamp of when it occurred. croak Will croak (see the Carp manpage) with the error, and add the timestamp of when it occurred. cluck Will cluck (see the Carp manpage) with the error, and add the timestamp of when it occurred. confess Will confess (see the Carp manpage) with the error, and add the timestamp of when it occurred die Will simply die with the error message of the item warn Will simply warn with the error message of the item trace Will provide a traceback of this error item back to the first one that occurred, clucking with every item as it comes across it. Custom Handlers If you wish to provide your own handlers, you can simply do the following: o Create a file that holds a package by the name of "Log::Message::Handlers" o Create subroutines with the same name as the levels you wish to handle in the Log::Message module (see the Log::Message manpage for explanation on levels) o Require that file in your program, or add it in your configuration (see the Log::Message::Config manpage for explanation on how to use a config file) And that is it, the handler will now be available to handle messages for you. The arguments a handler may receive are those specified by the "extra" key, when storing the message. See the Log::Message manpage for details on the arguments. SEE ALSO
Log::Message, Log::Message::Item, Log::Message::Config AUTHOR
This module by Jos Boumans <kane@cpan.org>. Acknowledgements Thanks to Ann Barcomb for her suggestions. COPYRIGHT
This module is copyright (c) 2002 Jos Boumans <kane@cpan.org>. All rights reserved. This library is free software; you may redistribute and/or modify it under the same terms as Perl itself. perl v5.16.2 2012-10-11 Log::Message::Handlers(3pm)
All times are GMT -4. The time now is 08:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy