Sponsored Content
Full Discussion: Join Function in PERL
Top Forums Shell Programming and Scripting Join Function in PERL Post 302427314 by durden_tyler on Friday 4th of June 2010 02:57:17 PM
Old 06-04-2010
Quote:
Originally Posted by thankful123
Its printing in a same line, all the file, the joining is not breaked if found date stamp.

2009-11-10 04:49:16,170 INFO handlers
b;
c;
ddaa;

2009-11-10 04:49:16,170 INFO handlers
aa;
bb;
cc;

OUTPUT:

2009-11-10 04:49:16,170 INFO handlers b; c; ddaa;
2009-11-10 04:49:16,170 INFO handlers aa; bb; cc;

...
Something like this maybe ?

Code:
$
$
$ cat f1
2009-11-10 04:49:16,170 INFO handlers
b;
c;
ddaa;

2009-11-10 04:49:16,170 INFO handlers
aa;
bb;
cc;
$
$
$ perl -ne 'chomp; if (/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d,.*$/ or /./){print $_," "} else {print "\n"} END {print "\n"}' f1
2009-11-10 04:49:16,170 INFO handlers b; c; ddaa;
2009-11-10 04:49:16,170 INFO handlers aa; bb; cc;
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

join function and -o and -a

I'm completing a join where I specify the outfile format....such as: join -t \| -j1 1 -j2 1 -o 1.1 1.2 1.3 2.4 1.5 1.6 1.7 $OUTFILE TMP_INFILE > NEW_OUTFILE Now this works great. Now what I also want is to include any unmatched rows from the first file...and I use the -a flag for this. ... (1 Reply)
Discussion started by: peter.herlihy
1 Replies

2. Shell Programming and Scripting

join 2 array in perl?

Hi guys, Can anyone tell me how to join 2 array together? @array1=("abc", "def"); @array2=("xyz", "uuu"); @join_array = fun(@array1,@array2); # @join_array == ("abc", "def", "xyz", "uuu") any function can do what fun(@@) does? thanks Gusla (2 Replies)
Discussion started by: gusla
2 Replies

3. Shell Programming and Scripting

oct function in perl

hi i came across one program which uses some method to calculate file permissions using lstat in perl and i am not getting how its doing that i am pasting the code below ... $ > cat b.pl use Fcntl':mode'; my... (0 Replies)
Discussion started by: zedex
0 Replies

4. Programming

sql,multiple join,outer join issue

example sql: select a.a1,b.b1,c.c1,d.d1,e.e1 from a left outer join b on a.x=b.x left outer join c on b.y=c.y left outer join d on d.z=a.z inner join a.t=e.t I know how single outer or inner join works in sql. But I don't really understand when there are multiple of them. can... (0 Replies)
Discussion started by: robbiezr
0 Replies

5. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

6. Shell Programming and Scripting

Function extraction in PERL

the log contains mathematical operation as follows fm_void_mathematics : PCM_OP_MATHS input function PIN_FLD_NUM1 INT 1 PIN_FLD_NUM2 INT 2 PIN_FLD_RESULTS int PIN_FLD_OUT INT * D Wed Sep 16 05:40:22 2009 solaris_testing fm_void_add : PIN_FLD_SUM int 3 D Wed Sep 16 05:40:22 2009... (1 Reply)
Discussion started by: vkca
1 Replies

7. Shell Programming and Scripting

Perl split and join

Hi, I have tried the split and join functions but stuck with unexpected results. Any help appreciated. I pass multiple values at command line like perl test.pl -type java,xml. This works good for me but i am not sure how to print it in the required format. Here is the code i tried:... (4 Replies)
Discussion started by: nmattam
4 Replies

8. UNIX for Dummies Questions & Answers

How to use the the join command to join multiple files by a common column

Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies

9. Shell Programming and Scripting

Problem of Perl's "join" function

$ perl -e '@f=("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","1","911"); print join("\t",@f)."\n";' aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ... (5 Replies)
Discussion started by: carloszhang
5 Replies

10. Shell Programming and Scripting

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies
TrapReceiver(3pm)					User Contributed Perl Documentation					 TrapReceiver(3pm)

NAME
NetSNMP::TrapReceiver - Embedded perl trap handling for Net-SNMP's snmptrapd SYNOPSIS
Put the following lines in your snmptrapd.conf file: perl NetSNMP::TrapReceiver::register("trapOID", &myfunc); ABSTRACT
The NetSNMP::TrapReceiver module is used to register perl subroutines into the Net-SNMP snmptrapd process. Net-SNMP MUST have been configured using --enable-embedded-perl. Registration of functions is then done through the snmptrapd.conf configuration file. This module can NOT be used in a normal perl script to receive traps. It is intended solely for embedded use within the snmptrapd demon. DESCRIPTION
Within the snmptrapd.conf file, the keyword "perl" may be used to call any perl expression and using this ability, you can use the NetSNMP::TrapReceiver module to register functions which will be called every time a given notification (a trap or an inform) is received. Registered functions are called with 2 arguments. The first is a reference to a hash containing information about how the trap was received (what version of the SNMP protocol was used, where it came from, what SNMP user name or community name it was sent under, etc). The second argument is a reference to an array containing the variable bindings (OID and value information) that define the noification itself. Each variable is itself a reference to an array containing three values: a NetSNMP::OID object, the value that came associated with it, and the value's numeric type (see NetSNMP::ASN for further details on SNMP typing information). Registered functions should return one of the following values: NETSNMPTRAPD_HANDLER_OK Handling the trap succeeded, but lets the snmptrapd demon check for further appropriate handlers. NETSNMPTRAPD_HANDLER_FAIL Handling the trap failed, but lets the snmptrapd demon check for further appropriate handlers. NETSNMPTRAPD_HANDLER_BREAK Stops evaluating the list of handlers for this specific trap, but lets the snmptrapd demon apply global handlers. NETSNMPTRAPD_HANDLER_FINISH Stops searching for further appropriate handlers. If a handler function does not return anything appropriate or even nothing at all, a return value of NETSNMPTRAPD_HANDLER_OK is assumed. Subroutines are registered using the NetSNMP::TrapReceiver::register function, which takes two arguments. The first is a string describing the notification you want to register for (such as "linkUp" or "MyMIB::MyTrap" or ".1.3.6.1.4.1.2021...."). Two special keywords can be used in place of an OID: "default" and "all". The "default" keyword indicates you want your handler to be called in the case where no other handlers are called. The "all" keyword indicates that the handler should ALWAYS be called for every notification. EXAMPLE
As an example, put the following code into a file (say "/usr/local/share/snmp/mytrapd.pl"): #!/usr/bin/perl sub my_receiver { print "********** PERL RECEIVED A NOTIFICATION: "; # print the PDU info (a hash reference) print "PDU INFO: "; foreach my $k(keys(%{$_[0]})) { if ($k eq "securityEngineID" || $k eq "contextEngineID") { printf " %-30s 0x%s ", $k, unpack('h*', $_[0]{$k}); } else { printf " %-30s %s ", $k, $_[0]{$k}; } } # print the variable bindings: print "VARBINDS: "; foreach my $x (@{$_[1]}) { printf " %-30s type=%-2d value=%s ", $x->[0], $x->[2], $x->[1]; } } NetSNMP::TrapReceiver::register("all", &my_receiver) || warn "failed to register our perl trap handler "; print STDERR "Loaded the example perl snmptrapd handler "; Then, put the following line in your snmprapd.conf file: perl do "/usr/local/share/snmp/mytrapd.pl"; Start snmptrapd (as root, and the following other opions make it stay in the foreground and log to stderr): snmptrapd -f -Le You should see it start up and display the final message from the end of the above perl script: Loaded the perl snmptrapd handler 2004-02-11 10:08:45 NET-SNMP version 5.2 Started. Then, if you send yourself a fake trap using the following example command: snmptrap -v 2c -c mycommunity localhost 0 linkUp ifIndex.1 i 1 ifAdminStatus.1 i up ifOperStatus.1 i up ifDescr s eth0 You should see the following output appear from snmptrapd as your perl code gets executed: ********** PERL RECEIVED A NOTIFICATION: PDU INFO: notificationtype TRAP receivedfrom 127.0.0.1 version 1 errorstatus 0 messageid 0 community mycommunity transactionid 2 errorindex 0 requestid 765160220 VARBINDS: sysUpTimeInstance type=67 value=0:0:00:00.00 snmpTrapOID.0 type=6 value=linkUp ifIndex.1 type=2 value=1 ifAdminStatus.1 type=2 value=1 ifOperStatus.1 type=2 value=1 ifDescr type=4 value="eth0" EXPORT
None by default. # =head2 Exportable constants # NETSNMPTRAPD_AUTH_HANDLER # NETSNMPTRAPD_HANDLER_BREAK # NETSNMPTRAPD_HANDLER_FAIL # NETSNMPTRAPD_HANDLER_FINISH # NETSNMPTRAPD_HANDLER_OK # NETSNMPTRAPD_POST_HANDLER # NETSNMPTRAPD_PRE_HANDLER SEE ALSO
NetSNMP::OID, NetSNMP::ASN snmptrapd.conf(5) for configuring the Net-SNMP trap receiver. snmpd.conf(5) for configuring the Net-SNMP snmp agent for sending traps. http://www.Net-SNMP.org/ AUTHOR
W. Hardaker, <hardaker@users.sourceforge.net> COPYRIGHT AND LICENSE
Copyright 2004 by W. Hardaker This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2009-10-29 TrapReceiver(3pm)
All times are GMT -4. The time now is 06:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy