Sponsored Content
Top Forums Shell Programming and Scripting Returning only part of a line when grepping Post 302410281 by durden_tyler on Monday 5th of April 2010 02:05:18 PM
Old 04-05-2010
Code:
$
$
$ # show the content of file "snort.rules"
$ cat snort.rules
blah
alert tcp any any -> 127.0.0.1 any (msg:"Example Message 1"; classtype:Example; sid:154987;)
blah blah
blah
alert tcp any any -> 127.0.0.1 any (msg:"Example Message 2"; classtype:Example; sid:198786;)
blah blah
blah
alert tcp any any -> 127.0.0.1 any (msg:"Example Message 3"; classtype:Example; sid:387984;)
blah blah
blah
alert tcp any any -> 127.0.0.1 any (msg:"Example Message 4"; classtype:Example; sid:123456;)
blah blah
blah
alert tcp any any -> 127.0.0.1 any (msg:"Example Message 5"; classtype:Example; sid:978165;)
blah blah
blah
alert tcp any any -> 127.0.0.1 any (msg:"Example Message 6"; classtype:Example; sid:654321;)
blah blah
$
$ # show the content of file "sids"
$ cat sids
154987
198786
387984
978165
$
$ # search and print all lines in file "snort.rules" that match the sids in file "sids"
$ grep -f sids snort.rules
alert tcp any any -> 127.0.0.1 any (msg:"Example Message 1"; classtype:Example; sid:154987;)
alert tcp any any -> 127.0.0.1 any (msg:"Example Message 2"; classtype:Example; sid:198786;)
alert tcp any any -> 127.0.0.1 any (msg:"Example Message 3"; classtype:Example; sid:387984;)
alert tcp any any -> 127.0.0.1 any (msg:"Example Message 5"; classtype:Example; sid:978165;)
$
$ # extract the message part from the result above, by using sed
$ grep -f sids snort.rules | sed 's/.*msg:"\(.*\)\".*/\1/'
Example Message 1
Example Message 2
Example Message 3
Example Message 5
$
$ # extract the message part from the result above, by using Perl
$ grep -f sids snort.rules | perl -plne 's/.*msg:"(.*)".*/$1/'
Example Message 1
Example Message 2
Example Message 3
Example Message 5
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grepping for something but excluding something else in the line

Ok heres the situation. I'm grepping for all running processes with the name system. but there are also processes running with the name systema. How do I just search for processes running just under the "system" user Thanks in advance (1 Reply)
Discussion started by: fusion99
1 Replies

2. Shell Programming and Scripting

grepping a part of filenames

Hi , I have a list of files in a directory and filename format is as follows: PQ223390 PQ876912 PQ768901 PQ398140 and so on I want to grep the first four digits of all the files after PQ, into a file. Ex: 2233 8769 6890 3981 and so on Can anyone tell me the command? thankx jazz (11 Replies)
Discussion started by: jazz
11 Replies

3. Shell Programming and Scripting

Grepping 1 line above and below pattern

I have a pattern:: xldn3176bap>arj SOCRATES_MAIN_LNX | grep " FA " 10/04/2007 21:01 10/04/2007 21:01 FA 1776752/1 1 I want the line above this line and the line below it too. Can anyone tell me how it can be done? - iAm4Free (4 Replies)
Discussion started by: iAm4Free
4 Replies

4. Shell Programming and Scripting

reading line by line and grepping

I've got a file which I am reading line by line (using read line) into a variable. I then want to do a grep on that line to check for something. I've tried a number of methods none of which seem to work. I thought I had it with the code below but for some reason it doesn't like it and comes... (4 Replies)
Discussion started by: QueryMaster
4 Replies

5. Shell Programming and Scripting

BASH: Grepping/sedding/etc out part of a file... (from one word to 'blank' line)

I have a file that lists data about a system. It has a part that can look like: the errors I'm looking for with other errors: Alerts Password Incorrect Login Error Another Error Another Error 2 Other Info or, just the errors I need to parse for: Alerts Password Incorrect ... (9 Replies)
Discussion started by: elinenbe
9 Replies

6. UNIX for Dummies Questions & Answers

Help with grepping and line number

I need help with extracting data from a large file ~900mb. Below is how the data looks like, line number value 1001 10000 ... ... 5001 50000 6001 60000 ... ... 10001 100000 ... ... 100001 ... (3 Replies)
Discussion started by: shabs1985
3 Replies

7. UNIX for Dummies Questions & Answers

Grepping nth line number

How do you grep every nth line number from a file? (2 Replies)
Discussion started by: shabs1985
2 Replies

8. Shell Programming and Scripting

Grepping file and returning passed variable if the value does not exist in file at all.

I have a list of fields that I want to check a file for, returning that field if it not found at all in the file. Is there a way to do a grep -lc and return the passed variable too rather then just the count? I am doing some crappy work-around now but I was not sure how to regrep this for :0 so... (3 Replies)
Discussion started by: personalt
3 Replies

9. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

10. Shell Programming and Scripting

Finding pattern in a text file and returning a part of the word

Dear All, assume that we have a text file or a folder of files, I want to find this pattern followers*.csv in the text file , and get * as the output. There are different matches and * means every character. Thank you in advance. Best, David (1 Reply)
Discussion started by: davidfreed
1 Replies
Net::DBus::Binding::Message(3pm)			User Contributed Perl Documentation			  Net::DBus::Binding::Message(3pm)

NAME
Net::DBus::Binding::Message - Base class for messages SYNOPSIS
Sending a message my $msg = new Net::DBus::Binding::Message::Signal; my $iterator = $msg->iterator; $iterator->append_byte(132); $iterator->append_int32(14241); $connection->send($msg); DESCRIPTION
Provides a base class for the different kinds of message that can be sent/received. Instances of this class are never instantiated directly, rather one of the four sub-types Net::DBus::Binding::Message::Signal, Net::DBus::Binding::Message::MethodCall, Net::DBus::Binding::Message::MethodReturn, Net::DBus::Binding::Message::Error should be used. CONSTANTS
The following constants are defined in this module. They are not exported into the caller's namespace & thus must be referenced with their fully qualified package names TYPE_ARRAY Constant representing the signature value associated with the array data type. TYPE_BOOLEAN Constant representing the signature value associated with the boolean data type. TYPE_BYTE Constant representing the signature value associated with the byte data type. TYPE_DICT_ENTRY Constant representing the signature value associated with the dictionary entry data type. TYPE_DOUBLE Constant representing the signature value associated with the IEEE double precision floating point data type. TYPE_INT16 Constant representing the signature value associated with the signed 16 bit integer data type. TYPE_INT32 Constant representing the signature value associated with the signed 32 bit integer data type. TYPE_INT64 Constant representing the signature value associated with the signed 64 bit integer data type. TYPE_OBJECT_PATH Constant representing the signature value associated with the object path data type. TYPE_STRING Constant representing the signature value associated with the UTF-8 string data type. TYPE_SIGNATURE Constant representing the signature value associated with the signature data type. TYPE_STRUCT Constant representing the signature value associated with the struct data type. TYPE_UINT16 Constant representing the signature value associated with the unsigned 16 bit integer data type. TYPE_UINT32 Constant representing the signature value associated with the unsigned 32 bit integer data type. TYPE_UINT64 Constant representing the signature value associated with the unsigned 64 bit integer data type. TYPE_VARIANT Constant representing the signature value associated with the variant data type. METHODS
my $msg = Net::DBus::Binding::Message->new(message => $rawmessage); Creates a new message object, initializing it with the underlying C message object given by the "message" object. This constructor is intended for internal use only, instead refer to one of the four sub-types for this class for specific message types my $type = $msg->get_type Retrieves the type code for this message. The returned value corresponds to one of the four "Net::DBus::Binding::Message::MESSAGE_TYPE_*" constants. my $interface = $msg->get_interface Retrieves the name of the interface targetted by this message, possibly an empty string if there is no applicable interface for this message. my $path = $msg->get_path Retrieves the object path associated with the message, possibly an empty string if there is no applicable object for this message. my $name = $msg->get_destination Retrieves the uniqe or well-known bus name for client intended to be the recipient of the message. Possibly returns an empty string if the message is being broadcast to all clients. my $name = $msg->get_sender Retireves the unique name of the client sending the message my $serial = $msg->get_serial Retrieves the unique serial number of this message. The number is guarenteed unique for as long as the connection over which the message was sent remains open. May return zero, if the message is yet to be sent. my $name = $msg->get_member For method calls, retrieves the name of the method to be invoked, while for signals, retrieves the name of the signal. my $sig = $msg->get_signature Retrieves a string representing the type signature of the values packed into the body of the message. $msg->set_sender($name) Set the name of the client sending the message. The name must be the unique name of the client. $msg->set_destination($name) Set the name of the intended recipient of the message. This is typically used for signals to switch them from broadcast to unicast. my $iterator = $msg->iterator; Retrieves an iterator which can be used for reading or writing fields of the message. The returned object is an instance of the "Net::DBus::Binding::Iterator" class. $boolean = $msg->get_no_reply() Gets the flag indicating whether the message is expecting a reply to be sent. $msg->set_no_reply($boolean) Toggles the flag indicating whether the message is expecting a reply to be sent. All method call messages expect a reply by default. By toggling this flag the communication latency is reduced by removing the need for the client to wait my @values = $msg->get_args_list De-marshall all the values in the body of the message, using the message signature to identify data types. The values are returned as a list. $msg->append_args_list(@values) Append a set of values to the body of the message. Values will be encoded as either a string, list or dictionary as appropriate to their Perl data type. For more specific data typing needs, the Net::DBus::Binding::Iterator object should be used instead. AUTHOR
Daniel P. Berrange COPYRIGHT
Copyright (C) 2004-2011 Daniel P. Berrange SEE ALSO
Net::DBus::Binding::Server, Net::DBus::Binding::Connection, Net::DBus::Binding::Message::Signal, Net::DBus::Binding::Message::MethodCall, Net::DBus::Binding::Message::MethodReturn, Net::DBus::Binding::Message::Error perl v5.14.2 2011-06-30 Net::DBus::Binding::Message(3pm)
All times are GMT -4. The time now is 02:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy