Sponsored Content
Top Forums Shell Programming and Scripting Find pattern, and then last field from subsequent lines Post 302370266 by Yorkie99 on Wednesday 11th of November 2009 01:57:32 AM
Old 11-11-2009
Hi... thanks for the suggestions... but they don't work. I'm working on Ubuntu rather than Solaris... wouldn't have thought it would make that much of a difference but it obviously does

steadyonabix: when I use that line, I get zero output
radoulov: when I use that line, I get mumbled junk, looks like the fields are overwriting each other
tip78: when I use that script, I just get loads of errors of type...

Use of uninitialized value $1 in concatenation (.) or string at ./test.pl line 7, <FH> line 1618.
Use of uninitialized value $1 in concatenation (.) or string at ./test.pl line 7, <FH> line 1619.
Use of uninitialized value $1 in concatenation (.) or string at ./test.pl line 7, <FH> line 1620.

Thanks for the suggestions though.. I'll keep looking at it.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find pattern and replace another field

HI all I have a problem, I need to replace a field in a file, but only in the lines that have some pattern, example: 100099C01101C00000000059394200701CREoperadora_TX 100099C01201C00000000000099786137OPERADORA_TX2 in the example above I need to change the first field from 1 to 2 only if... (3 Replies)
Discussion started by: sergiioo
3 Replies

2. Shell Programming and Scripting

Displaying lines of a file where the second field matches a pattern

Howdy. I know this is most likely possible using sed or awk or grep, most likely a combination of them together, but how would one go about running a grep like command on a file where you only try to match your pattern to the second field in a line, space delimited? Example: You are... (3 Replies)
Discussion started by: LordJezoX
3 Replies

3. Shell Programming and Scripting

awk text record - prepend first field to all subsequent fields

Hello everyone, I've suddenly gotten very interested in sed and awk (and enjoying it quite a bit too) because of a large conversion project that we're working on. I'm currently stuck with a very inefficient process for processing text blocks. I'm sure someone here should be able to easily point out... (2 Replies)
Discussion started by: jameswatson3
2 Replies

4. Shell Programming and Scripting

awk - use fields from subsequent lines

I've run into a problem getting exactly what I want out of awk - some folks may recognize this as an output from Amazon's ec2-describe-instances: Given the following: INSTANCE i-4960f321 BLOCKDEVICE Line2Var2 TAG instance i-4960f321 Name web1 TAG instance i-4960f321... (2 Replies)
Discussion started by: colinjohnson
2 Replies

5. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

6. UNIX for Advanced & Expert Users

Need command for grepping pattern lines with subsequent lines

Hi, I have a requirement like, I have a list of pattens in a file say pattern.txt, PHC111 PHC113 and in another file called master.lst i have entries like, PHC111 a b PHC112 a PHC113 b c PHC114 d e (5 Replies)
Discussion started by: rbalaj16
5 Replies

7. Shell Programming and Scripting

Awk: print lines with one of multiple pattern in the same field (column)

Hi all, I am new to using awk and am quickly discovering what a powerful pattern-recognition tool it is. However, I have what seems like a fairly basic task that I just can't figure out how to perform in one line. I want awk to find and print all the lines in which one of multiple patterns (e.g.... (8 Replies)
Discussion started by: elgo4
8 Replies

8. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

9. Shell Programming and Scripting

Find pattern in first field of file

Hello all I have two files. 1. Pattern.txt - It contains patterns to be matched. It has large number of patterns to be matched. Cat Pattern.txt Ram Shyam Mohan Jhon I have another file which has actual data and records are delimted by single or multiple spaces. 2.... (8 Replies)
Discussion started by: krsnadasa
8 Replies

10. Shell Programming and Scripting

Print field after pattern in all lines

data: hello--hello1--hello2--#growncars#vello--hello3--hello4--jello#growncars#dello--gello--gelloA--gelloB#growncars# I want to be able to print all the values that are found between the patterns "#growncars#" and the next "#growncars#" on the same line. so the output should be: ... (8 Replies)
Discussion started by: SkySmart
8 Replies
Warn(3) 						User Contributed Perl Documentation						   Warn(3)

NAME
Test::Warn - Perl extension to test methods for warnings SYNOPSIS
use Test::Warn; warning_is {foo(-dri => "/")} "Unknown Parameter 'dri'", "dri != dir gives warning"; warnings_are {bar(1,1)} ["Width very small", "Height very small"]; warning_is {add(2,2)} undef, "No warnings for calc 2+2"; # or warnings_are {add(2,2)} [], "No warnings for calc 2+2"; # what reads better :-) warning_like {foo(-dri => "/")} qr/unknown param/i, "an unknown parameter test"; warnings_like {bar(1,1)} [qr/width.*small/i, qr/height.*small/i]; warning_is {foo()} {carped => "didn't find the right parameters"}; warnings_like {foo()} [qr/undefined/,qr/undefined/,{carped => qr/no result/i}]; warning_like {foo(undef)} 'uninitialized'; warning_like {bar(file => '/etc/passwd')} 'io'; warning_like {eval q/"$x"; $x;/} [qw/void uninitialized/], "some warnings at compile time"; warnings_exist {...} [qr/expected warning/], "Expected warning is thrown"; DESCRIPTION
A good style of Perl programming calls for a lot of diverse regression tests. This module provides a few convenience methods for testing warning based code. If you are not already familiar with the Test::More manpage now would be the time to go take a look. FUNCTIONS warning_is BLOCK STRING, TEST_NAME Tests that BLOCK gives the specified warning exactly once. The test fails if the BLOCK warns more than once or does not warn at all. If the string is undef, then the tests succeeds if the BLOCK doesn't give any warning. Another way to say that there are no warnings in the block is "warnings_are {foo()} [], "no warnings"". If you want to test for a warning given by Carp, you have to write something like: "warning_is {carp "msg"} {carped => 'msg'}, "Test for a carped warning"". The test will fail if a "normal" warning is found instead of a "carped" one. Note: "warn "foo"" would print something like "foo at -e line 1". This method ignores everything after the "at". Thus to match this warning you would have to call "warning_is {warn "foo"} "foo", "Foo succeeded"". If you need to test for a warning at an exactly line, try something like "warning_like {warn "foo"} qr/at XYZ.dat line 5/". warning_is and warning_are are only aliases to the same method. So you also could write "warning_is {foo()} [], "no warning"" or something similar. I decided to give two methods the same name to improve readability. A true value is returned if the test succeeds, false otherwise. The test name is optional, but recommended. warnings_are BLOCK ARRAYREF, TEST_NAME Tests to see that BLOCK gives exactly the specified warnings. The test fails if the warnings from BLOCK are not exactly the ones in ARRAYREF. If the ARRAYREF is equal to [], then the test succeeds if the BLOCK doesn't give any warning. Please read also the notes to warning_is as these methods are only aliases. If you want more than one test for carped warnings, try this: "warnings_are {carp "c1"; carp "c2"} {carped =" ['c1','c2'];> or "warnings_are {foo()} ["Warning 1", {carped =" ["Carp 1", "Carp 2"]}, "Warning 2"]>. Note that "{carped =" ...}> must always be a hash ref. warning_like BLOCK REGEXP, TEST_NAME Tests that BLOCK gives exactly one warning and it can be matched by the given regexp. If the string is undef, then the tests succeeds if the BLOCK doesn't give any warning. The REGEXP is matched against the whole warning line, which in general has the form "WARNING at __FILE__ line __LINE__". So you can check for a warning in the file Foo.pm on line 5 with "warning_like {bar()} qr/at Foo.pm line 5/, "Testname"". I don't know whether it's sensful to do such a test :-( However, you should be prepared as a matching with 'at', 'file', 'd' or similar will always pass. Think to the qr/^foo/ if you want to test for warning "foo something" in file foo.pl. You can also write the regexp in a string as "/.../" instead of using the qr/.../ syntax. Note that the slashes are important in the string, as strings without slashes are reserved for warning categories (to match warning categories as can be seen in the perllexwarn man page). Similar to "warning_is", you can test for warnings via "carp" with: "warning_like {bar()} {carped =" qr/bar called too early/i};> Similar to "warning_is"/"warnings_are", "warning_like" and "warnings_like" are only aliases to the same methods. A true value is returned if the test succeeds, false otherwise. The test name is optional, but recommended. warning_like BLOCK STRING, TEST_NAME Tests whether a BLOCK gives exactly one warning of the passed category. The categories are grouped in a tree, like it is expressed in perllexwarn. Note, that they have the hierarchical structure from perl 5.8.0, wich has a little bit changed to 5.6.1 or earlier versions (You can access the internal used tree with $Test::Warn::Categorization::tree, although I wouldn't recommend it) Thanks to the grouping in a tree, it's simple possible to test for an 'io' warning, instead for testing for a 'closed|exec|layer|newline|pipe|unopened' warning. Note, that warnings occuring at compile time, can only be catched in an eval block. So warning_like {eval q/"$x"; $x;/} [qw/void uninitialized/], "some warnings at compile time"; will work, while it wouldn't work without the eval. Note, that it isn't possible yet, to test for own categories, created with warnings::register. warnings_like BLOCK ARRAYREF, TEST_NAME Tests to see that BLOCK gives exactly the number of the specified warnings and all the warnings have to match in the defined order to the passed regexes. Please read also the notes to warning_like as these methods are only aliases. Similar to "warnings_are", you can test for multiple warnings via "carp" and for warning categories, too: warnings_like {foo()} [qr/bar warning/, qr/bar warning/, {carped => qr/bar warning/i}, 'io' ], "I hope, you'll never have to write a test for so many warnings :-)"; warnings_exist BLOCK STRING|ARRAYREF, TEST_NAME Same as warning_like, but will warn() all warnings that do not match the supplied regex/category, instead of registering an error. Use this test when you just want to make sure that specific warnings were generated, and couldn't care less if other warnings happened in the same block of code. warnings_exist {...} [qr/expected warning/], "Expected warning is thrown"; warnings_exist {...} ['uninitialized'], "Expected warning is thrown"; EXPORT "warning_is", "warnings_are", "warning_like", "warnings_like", "warnings_exist" by default. BUGS
Please note that warnings with newlines inside are making a lot of trouble. The only sensible way to handle them is to use are the "warning_like" or "warnings_like" methods. Background for these problems is that there is no really secure way to distinguish between warnings with newlines and a tracing stacktrace. If a method has it's own warn handler, overwriting $SIG{__WARN__}, my test warning methods won't get these warnings. The "warning_like BLOCK CATEGORY, TEST_NAME" method isn't extremely tested. Please use this calling style with higher attention and tell me if you find a bug. TODO
Improve this documentation. The code has some parts doubled - especially in the test scripts. This is really awkward and must be changed. Please feel free to suggest improvements. SEE ALSO
Have a look to the similar modules: Test::Exception, Test::Trap. THANKS
Many thanks to Adrian Howard, chromatic and Michael G. Schwern, who have given me a lot of ideas. AUTHOR
Janek Schleicher, <bigj AT kamelfreund.de> COPYRIGHT AND LICENSE
Copyright 2002 by Janek Schleicher Copyright 2007-2011 by Alexandr Ciornii, <http://chorny.net/> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.2 2012-03-31 Warn(3)
All times are GMT -4. The time now is 07:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy