Sponsored Content
Top Forums Shell Programming and Scripting Capture lines based on keywords Post 88400 by futurelet on Thursday 3rd of November 2005 04:30:52 PM
Old 11-03-2005
Code:
awk '$0 ~ "key1.*" var, /key2/' var="foo" infile

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to keep appending a newly created file based on some keywords

Hi Friends, I have to create a new log file everyday and append it with content based on some keywords found in another log file. Here is what I have tried so far... grep Error /parentfolder/someLogFile.log >> /parentfolder /Archive/"testlogfile_error_`date '+%d%m%y'`.txt" grep error... (6 Replies)
Discussion started by: supreet
6 Replies

2. Shell Programming and Scripting

How to search for keywords in subsequent lines

Hi all, I am looking for a coomand to search for the keywords in susequenct lines. Keyword1 in a line and Keyword2 in the very next line. Once i found the combination ineed to print the lines with patterns and the line above and one below. I am giving an example here: Keywords are :ERROR and... (12 Replies)
Discussion started by: rdhanek
12 Replies

3. UNIX for Advanced & Expert Users

Forwarding based on keywords in sendmail

I have an application that runs on the server with root privileges and all emails it sends get sent to root (errors, logs, etc), when they should actually go to one of application admins. I would like to separate these emails from the OS related one sent to root and forward them to that... (2 Replies)
Discussion started by: vostrushka
2 Replies

4. Shell Programming and Scripting

Sorting lines based on keywords for MySQL script

the thing which i require is very very complex.. i tried hard to find the solution but couldnt.. the thing i need to achieve is say i have a file cat delta.sql CREATE VIEW Austin Etc etc . . . CREATE VIEW Barabara AS SELECT blah blah blah FROM Austin z, Cluster s, Instance i WHERE... (4 Replies)
Discussion started by: vivek d r
4 Replies

5. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

6. Shell Programming and Scripting

Extracting words and lines based on keywords

Hello! I'm trying to process a text file and am stuck at 2 extractions. Hoping someone can help me here: 1. Given a line in a text file and given a keyword, how can I extract the word preceeding the keyword using a shell command/script? For example: Given a keyword "world" in the line: ... (2 Replies)
Discussion started by: seemad
2 Replies

7. Shell Programming and Scripting

Display lines between keywords inclusive

Hi, I have a file that contains a lot of lines that are repetitive. I am interested in grepping the following section which is repetitive. ::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::: <Address> <Street>xxxy</Street> ... (3 Replies)
Discussion started by: jakSun8
3 Replies

8. Shell Programming and Scripting

awk to print line based on two keywords

I am starting to write a multi-line awk and using the file below which is tab-delimited, print only the line with oncomineGeneClass and oncomineVariantClass and PASS. The script execute but seems to be printing the entire file, not the desired line. Thank you :). file ... (8 Replies)
Discussion started by: cmccabe
8 Replies

9. Shell Programming and Scripting

Split content based on keywords

I need to split the file contents with multiple rows based on patterns Sample: Input: ABC101testXYZ102UKMNO1092testing ABC999testKMNValid Output: ABC101test XYZ102U KMN1092testing ABC999test KMNValid In this ABC , XYZ and KMN are patterns Continue here./mod] Please read forum... (1 Reply)
Discussion started by: Jairaj
1 Replies

10. UNIX for Beginners Questions & Answers

Split content based on keywords

I need to split the file contents with multiple rows based on patterns Sample: Input: ABC101testXYZ102UKMNO1092testing ABC999testKMNValid Output: ABC101test XYZ102U KMN1092testing ABC999test KMNValid In this ABC , XYZ and KMN are patterns (6 Replies)
Discussion started by: Jairaj
6 Replies
Data::OptList(3)					User Contributed Perl Documentation					  Data::OptList(3)

NAME
Data::OptList - parse and validate simple name/value option pairs VERSION
version 0.109 SYNOPSIS
use Data::OptList; my $options = Data::OptList::mkopt([ qw(key1 key2 key3 key4), key5 => { ... }, key6 => [ ... ], key7 => sub { ... }, key8 => { ... }, key8 => [ ... ], ]); ...is the same thing, more or less, as: my $options = [ [ key1 => undef, ], [ key2 => undef, ], [ key3 => undef, ], [ key4 => undef, ], [ key5 => { ... }, ], [ key6 => [ ... ], ], [ key7 => sub { ... }, ], [ key8 => { ... }, ], [ key8 => [ ... ], ], ]); DESCRIPTION
Hashes are great for storing named data, but if you want more than one entry for a name, you have to use a list of pairs. Even then, this is really boring to write: $values = [ foo => undef, bar => undef, baz => undef, xyz => { ... }, ]; Just look at all those undefs! Don't worry, we can get rid of those: $values = [ map { $_ => undef } qw(foo bar baz), xyz => { ... }, ]; Aaaauuugh! We've saved a little typing, but now it requires thought to read, and thinking is even worse than typing... and it's got a bug! It looked right, didn't it? Well, the "xyz => { ... }" gets consumed by the map, and we don't get the data we wanted. With Data::OptList, you can do this instead: $values = Data::OptList::mkopt([ qw(foo bar baz), xyz => { ... }, ]); This works by assuming that any defined scalar is a name and any reference following a name is its value. FUNCTIONS
mkopt my $opt_list = Data::OptList::mkopt($input, \%arg); Valid arguments are: moniker - a word used in errors to describe the opt list; encouraged require_unique - if true, no name may appear more than once must_be - types to which opt list values are limited (described below) name_test - a coderef used to test whether a value can be a name (described below, but you probably don't want this) This produces an array of arrays; the inner arrays are name/value pairs. Values will be either "undef" or a reference. Positional parameters may be used for compatibility with the old "mkopt" interface: my $opt_list = Data::OptList::mkopt($input, $moniker, $req_uni, $must_be); Valid values for $input: undef -> [] hashref -> [ [ key1 => value1 ] ... ] # non-ref values become undef arrayref -> every name followed by a non-name becomes a pair: [ name => ref ] every name followed by undef becomes a pair: [ name => undef ] otherwise, it becomes [ name => undef ] like so: [ "a", "b", [ 1, 2 ] ] -> [ [ a => undef ], [ b => [ 1, 2 ] ] ] By default, a name is any defined non-reference. The "name_test" parameter can be a code ref that tests whether the argument passed it is a name or not. This should be used rarely. Interactions between "require_unique" and "name_test" are not yet particularly elegant, as "require_unique" just tests string equality. This may change. The "must_be" parameter is either a scalar or array of scalars; it defines what kind(s) of refs may be values. If an invalid value is found, an exception is thrown. If no value is passed for this argument, any reference is valid. If "must_be" specifies that values must be CODE, HASH, ARRAY, or SCALAR, then Params::Util is used to check whether the given value can provide that interface. Otherwise, it checks that the given value is an object of the kind. In other words: [ qw(SCALAR HASH Object::Known) ] Means: _SCALAR0($value) or _HASH($value) or _INSTANCE($value, 'Object::Known') mkopt_hash my $opt_hash = Data::OptList::mkopt_hash($input, $moniker, $must_be); Given valid "mkopt" input, this routine returns a reference to a hash. It will throw an exception if any name has more than one value. EXPORTS
Both "mkopt" and "mkopt_hash" may be exported on request. AUTHOR
Ricardo Signes <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2006 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.18.2 2013-12-13 Data::OptList(3)
All times are GMT -4. The time now is 07:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy