Sponsored Content
Top Forums Shell Programming and Scripting awk to combine all matching dates and remove non-matching Post 302985598 by RavinderSingh13 on Saturday 12th of November 2016 11:01:34 AM
Old 11-12-2016
Hello cmccabe,

If your Input_file is exactly the same as sample shown into your post then following may help you in same.
Code:
awk -F, '{if(A!=$1 && A && VAL ~ /,/){print VAL;VAL=""};VAL=A==$1?VAL OFS $2 OFS $3:$0;A=$1} END{print VAL}'   Input_file

Output will be as follows.
Code:
20161109104500.0+0000,x,5631 y 2 z 2 a 4117 b 6182 c 1556
20161109104500.0+0000,k,2689 l 6182 d 3241 e 2418 f 26 g 285166.843750 h 67216

NOTE: Above code considers that the 1st fields we have to match are on the basis of there next line not the whole Input_file. Input_file's non-matching lines will not have comma(,) in them.

If you have mor requirements in this, request you to be more clear into your post so that could try to help you more on same. I hope this helps.

Thanks,
R. Singh

Last edited by RavinderSingh13; 11-12-2016 at 02:01 PM..
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove matching lines with list of strings

Hi, HP-UX gxxxxxxxc B.11.23 U ia64 3717505098 unlimited-user license I have a file with below pipe separated field values: xxx|xxx|abcd|xxx|xxx|xx xxx|xxx|abcd#123|xxx|xxx|xx xxx|xxx|abcd#345|xxx|xxx|xx xxx|xxx|pqrs|xxx|xxx|xx xxx|xxx|pqrs#123|xxx|xxx|xx The third field has values like... (6 Replies)
Discussion started by: Nanu_Manju
6 Replies

2. Shell Programming and Scripting

How to remove all words from a matching word in a line?

Hi Guys, :p I have a file like this: 2010-04-25 00:00:30,095 INFO - ]- start process U100M4 2010-04-25 00:00:30,096 DEBUG - ] -- call EJB 2010-04-25 00:00:30,709 INFO - - end processU100M4 2010-04-25 00:00:30,710 DEBUG - got message=Sorry I want to out put format. 2010-04-25... (5 Replies)
Discussion started by: ooilinlove
5 Replies

3. Shell Programming and Scripting

awk: matching and not matching

Hello all, simple matching and if not match problem that i can't figure out. file1 hostname: 30 10 * * * /home/toto/start PROD instance_name1 -p 00 9 * * * /home/toto/start PROD instance_name2 -p 15 8 * * * /home/toto/start PROD instance_name3 -p hostname2: 00 8 * * *... (5 Replies)
Discussion started by: maverick72
5 Replies

4. Shell Programming and Scripting

Insert lines above matching line with content from matching

Hi, I have text file: Name: xyz Gender: M Address: "120_B_C; ksilskdj; lsudlfw" Zip: 20392 Name: KLM Gender: F Address: "65_D_F; wnmlsi;lsuod;,...." Zip:90233I want to insert 2 new lines before the 'Address: ' line deriving value from this Address line value The Address value in quotes... (1 Reply)
Discussion started by: ysrini
1 Replies

5. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

6. Linux

Remove matching files from a list

hi, i have a cache file with below file list more gtda_11.cache GTDA_Dly_Pmix_GB_6_20130624.20130624070610.psv GTDA_Dly_Pmix_CH_006_20130624.20130624140018.psv GTDA_Dly_Pmix_GB_6_20130624.20130624070620.psv GTDA_Dly_Pmix_BE_6_20130624.20130624070620.psv... (2 Replies)
Discussion started by: renuk
2 Replies

7. Shell Programming and Scripting

awk to combine matching lines in file

I am trying to combine all matching lines in the tab-delimited using awk. The below runs but no output results. Thank you :). input chrX 110925349 110925532 ALG13 chrX 110925349 110925532 ALG13 chrX 110925349 110925532 ALG13 chrX 47433390 47433999 SYN1... (3 Replies)
Discussion started by: cmccabe
3 Replies

8. Shell Programming and Scripting

Remove lines matching a substring in a specific column

Dear group, I have following input text file: Brit 2016 11 18 12 00 10 1.485,00 EUR Brit 2016 11 18 12 00 10 142,64 EUR Brit 2016 11 18 12 00 10 19,80 EUR Brit 2016 11 18 12 00 10 545,00 EUR Brit 2016 11 18 12 00 10 6.450,00 EUR... (3 Replies)
Discussion started by: gfhsd
3 Replies

9. Shell Programming and Scripting

awk to combine all matching fields in input but only print line with largest value in specific field

In the below I am trying to use awk to match all the $13 values in input, which is tab-delimited, that are in $1 of gene which is just a single column of text. However only the line with the greatest $9 value in input needs to be printed. So in the example below all the MECP2 and LTBP1... (0 Replies)
Discussion started by: cmccabe
0 Replies

10. Shell Programming and Scripting

Remove lines with Pattren Matching

Hi , I need to remove the lines that matches the pattern TABLEEXCLUDE *.AQ$_*_F ; * is wildcard, it can be any word. For example, I have following file: TABLEEXCLUDE THOT.AQ$_PT_ADDR_CLEANUP_QTAB2_F ; TABLEEXCLUDE THOT.AQ$_MICRO_SERVICE_QT_F ; TEST TABLEEXCLUDE... (1 Reply)
Discussion started by: rcc50886
1 Replies
UNIVERSAL(3pm)						 Perl Programmers Reference Guide					    UNIVERSAL(3pm)

NAME
UNIVERSAL - base class for ALL classes (blessed references) SYNOPSIS
$is_io = $fd->isa("IO::Handle"); $is_io = Class->isa("IO::Handle"); $does_log = $obj->DOES("Logger"); $does_log = Class->DOES("Logger"); $sub = $obj->can("print"); $sub = Class->can("print"); $sub = eval { $ref->can("fandango") }; $ver = $obj->VERSION; # but never do this! $is_io = UNIVERSAL::isa($fd, "IO::Handle"); $sub = UNIVERSAL::can($obj, "print"); DESCRIPTION
"UNIVERSAL" is the base class from which all blessed references inherit. See perlobj. "UNIVERSAL" provides the following methods: "$obj->isa( TYPE )" "CLASS->isa( TYPE )" "eval { VAL->isa( TYPE ) }" Where "TYPE" is a package name $obj is a blessed reference or a package name "CLASS" is a package name "VAL" is any of the above or an unblessed reference When used as an instance or class method ("$obj->isa( TYPE )"), "isa" returns true if $obj is blessed into package "TYPE" or inherits from package "TYPE". When used as a class method ("CLASS->isa( TYPE )", sometimes referred to as a static method), "isa" returns true if "CLASS" inherits from (or is itself) the name of the package "TYPE" or inherits from package "TYPE". If you're not sure what you have (the "VAL" case), wrap the method call in an "eval" block to catch the exception if "VAL" is undefined. If you want to be sure that you're calling "isa" as a method, not a class, check the invocand with "blessed" from Scalar::Util first: use Scalar::Util 'blessed'; if ( blessed( $obj ) && $obj->isa("Some::Class") ) { ... } "$obj->DOES( ROLE )" "CLASS->DOES( ROLE )" "DOES" checks if the object or class performs the role "ROLE". A role is a named group of specific behavior (often methods of particular names and signatures), similar to a class, but not necessarily a complete class by itself. For example, logging or serialization may be roles. "DOES" and "isa" are similar, in that if either is true, you know that the object or class on which you call the method can perform specific behavior. However, "DOES" is different from "isa" in that it does not care how the invocand performs the operations, merely that it does. ("isa" of course mandates an inheritance relationship. Other relationships include aggregation, delegation, and mocking.) By default, classes in Perl only perform the "UNIVERSAL" role, as well as the role of all classes in their inheritance. In other words, by default "DOES" responds identically to "isa". There is a relationship between roles and classes, as each class implies the existence of a role of the same name. There is also a relationship between inheritance and roles, in that a subclass that inherits from an ancestor class implicitly performs any roles its parent performs. Thus you can use "DOES" in place of "isa" safely, as it will return true in all places where "isa" will return true (provided that any overridden "DOES" and "isa" methods behave appropriately). "$obj->can( METHOD )" "CLASS->can( METHOD )" "eval { VAL->can( METHOD ) }" "can" checks if the object or class has a method called "METHOD". If it does, then it returns a reference to the sub. If it does not, then it returns undef. This includes methods inherited or imported by $obj, "CLASS", or "VAL". "can" cannot know whether an object will be able to provide a method through AUTOLOAD (unless the object's class has overridden "can" appropriately), so a return value of undef does not necessarily mean the object will not be able to handle the method call. To get around this some module authors use a forward declaration (see perlsub) for methods they will handle via AUTOLOAD. For such 'dummy' subs, "can" will still return a code reference, which, when called, will fall through to the AUTOLOAD. If no suitable AUTOLOAD is provided, calling the coderef will cause an error. You may call "can" as a class (static) method or an object method. Again, the same rule about having a valid invocand applies -- use an "eval" block or "blessed" if you need to be extra paranoid. "VERSION ( [ REQUIRE ] )" "VERSION" will return the value of the variable $VERSION in the package the object is blessed into. If "REQUIRE" is given then it will do a comparison and die if the package version is not greater than or equal to "REQUIRE", or if either $VERSION or "REQUIRE" is not a "lax" version number (as defined by the version module). The return from "VERSION" will actually be the stringified version object using the package $VERSION scalar, which is guaranteed to be equivalent but may not be precisely the contents of the $VERSION scalar. If you want the actual contents of $VERSION, use $CLASS::VERSION instead. "VERSION" can be called as either a class (static) method or an object method. WARNINGS
NOTE: "can" directly uses Perl's internal code for method lookup, and "isa" uses a very similar method and cache-ing strategy. This may cause strange effects if the Perl code dynamically changes @ISA in any package. You may add other methods to the UNIVERSAL class via Perl or XS code. You do not need to "use UNIVERSAL" to make these methods available to your program (and you should not do so). EXPORTS
None by default. You may request the import of three functions ("isa", "can", and "VERSION"), but this feature is deprecated and will be removed. Please don't do this in new code. For example, previous versions of this documentation suggested using "isa" as a function to determine the type of a reference: use UNIVERSAL 'isa'; $yes = isa $h, "HASH"; $yes = isa "Foo", "Bar"; The problem is that this code will never call an overridden "isa" method in any class. Instead, use "reftype" from Scalar::Util for the first case: use Scalar::Util 'reftype'; $yes = reftype( $h ) eq "HASH"; and the method form of "isa" for the second: $yes = Foo->isa("Bar"); perl v5.18.2 2013-11-04 UNIVERSAL(3pm)
All times are GMT -4. The time now is 02:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy