extract string and sending it into a new file in perl program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract string and sending it into a new file in perl program
# 1  
Old 05-18-2010
extract string and sending it into a new file in perl program

Hi,

I have a input file with following values

(test.out)
Code:
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
export test: Processed 224000 entries
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
export test: Processed 224000 entries
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
export test: Processed 224000 entries
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery

I would like to grep all lines with word 'PANIC' and sent it another file using perl program with grep command. I have been trying different ways and not working. Pls advice. Thanks a lot for the help.

--example--
Code:
#!/usr/bin/perl

use strict;
use Mail::Sender;

my $extractname = $ARGV[0];
grep "PANIC" test.out > /tmp/PANIC;


Last edited by Franklin52; 05-18-2010 at 04:11 PM.. Reason: Please use code tags!
# 2  
Old 05-18-2010
If you want to do it thru ur perl script one of the following methods may work :

1) system("grep "PANIC" test.out > /tmp/PANIC");
2) `grep "PANIC" test.out > /tmp/PANIC`
# 3  
Old 05-18-2010
Code:
$
$
$ cat test.out
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
export test: Processed 224000 entries
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
export test: Processed 224000 entries
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
export test: Processed 224000 entries
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
$
$
$ perl -lne 'BEGIN {open(OUT, ">panic.txt")} /PANIC/ && print OUT $_; END{close(OUT)}' test.out
$
$
$ cat panic.txt
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
[ DEBUG - conn=-1 op=-1 msgId=-1 - libdb: PANIC: fatal region error detected; run recovery
$
$

tyler_durden
# 4  
Old 05-19-2010
Thanks a lot for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract n-digits from string in perl

Hello, I have a log file with logs such as 01/05/2017 10:23:41 : file.log.38: database error, MODE=SINGLE, LEVEL=critical, STATE: 01170255 (mode main how can i use perl to extract the 8-digit number below from the string 01170255 Thanks (7 Replies)
Discussion started by: james2009
7 Replies

2. Shell Programming and Scripting

Extract a string between 2 ref string from a file

Hi, May i ask if someone share some command for extracting a string between 2 ref string in a txt file My objective: i had a file with multiple lines and wants only to extract the string "watch?v=IbkAXOmEHpY" or "watch?v=<11 random character>", when i used "grep 'watch?=*' i got a results per... (4 Replies)
Discussion started by: jao_madn
4 Replies

3. Shell Programming and Scripting

Sending zip file as attachments in perl

Hi All, i have a code, where that script is sending mail to the users, but i want to enhance it, i.e i need to add attachment(zip file) to that, i dont want to use MIME:LITE module or any other module, with this simple code, i need to enhance. below is my code my %mail_params = (HTML ... (13 Replies)
Discussion started by: asak
13 Replies

4. 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

5. Shell Programming and Scripting

Sending email and attachment file using Perl

I am trying to send an email body of information and also attachment using perl script, but I am only able to send the body but not an attachment. is there around it without using "use MIME::Lite;" module. $user = "bataf\@xyz.com"; $subjectt = "mail from perl"; open(MAIL, "| mailx -s... (1 Reply)
Discussion started by: bataf
1 Replies

6. Shell Programming and Scripting

Perl REGEX - How do extract a string in a line?

Hi Guys, In the following line: cn=portal.090710.191533.428571000,cn=groups,dc=mp,dc=rj,dc=gov,dc=br I need to extract this string: portal.090710.191533.428571000 As you can see this string always will be bettween "cn=" and "," strings. Someone know one regular expression to... (4 Replies)
Discussion started by: maverick-ski
4 Replies

7. Shell Programming and Scripting

Perl and sending file to server

Hi, I am trying to write some test code for bigger project where my perl script will send file over to server. This is the current SERVER and CLIENT code I have so far. When I type "hi" from client I get hello back from server and like wise I send send command I get respond back the problem... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

8. Shell Programming and Scripting

Perl Extract String

Hi, I have a string like "something is good wanted (bla bla)" I need to get the world "wanted" from this string and "assign it to a variable".. but it's not a static word so i want to get that word by searching the pattern as follows <space>desiredword<space>( and i tried to get that... (6 Replies)
Discussion started by: xlynx3
6 Replies

9. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

10. Shell Programming and Scripting

perl newbie: how to extract an unknown word from a string

hi, im quite new to perl regexp. i have a problem where i want to extract a word from a given string. but the word is unknown, only fact is that it appears as the second word in the string. Eg. input string(s) : char var1 = 'A'; int var2 = 10; char *ptr; and what i want to do is... (3 Replies)
Discussion started by: wolwy_pete
3 Replies
Login or Register to Ask a Question