Sponsored Content
Top Forums Shell Programming and Scripting Merge lines in text file based on pattern Post 302391330 by Bertik on Monday 1st of February 2010 03:36:28 AM
Old 02-01-2010
Question Merge lines in text file based on pattern

Hello,

I have searched forum trying to find a solution to my problem, but could not find anything or I did not understand the examples....

I should say, I am very inexperienced with text processing.

I have a text file with approx 60k lines in it.
I need to merge lines based on the number on the end of the "master line".

Example1:
Code:
Word|1
(1)|Wordel|One Word

So, here I need to delete one pipe character and number 1 after the word 'Word' and merge first line with second line. Delete number 1 and this "(" and this ")" characters. Result should look like this:
Code:
Word|Wordel|One Word

Example 2:
Code:
Eye|4
(1)|Human Eye|Animal Eye
(2)|My Eye|Your Eye|His Eye|Her Eye
(3)|Second Eye|Third Eye
(4)|So Much About Eye

Here I need to delete one pipe character and number 4 after the word 'Eye' and merge first line with four following lines. Delete number 1 and 2 and 3 and 4 and this "(" and this ")" characters. Result should look like this:
Code:
Eye|Human Eye|Animal Eye|My Eye|Your Eye|His Eye|Her Eye|Second Eye|Third Eye|So Much About Eye

So, if the txt file looks like this before processing:
Code:
Word|1
(1)|Wordel|One Word
Eye|4
(1)|Human Eye|Animal Eye
(2)|My Eye|Your Eye|His Eye|Her Eye
(3)|Second Eye|Third Eye
(4)|So Much About Eye

I need it look like this after processing:
Code:
Word|Wordel|One Word
Eye|Human Eye|Animal Eye|My Eye|Your Eye|His Eye|Her Eye|Second Eye|Third Eye|So Much About Eye

Could somebody help me with this please?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge lines in Flat file based on first 5 characters

Hi I have the fixed width flat file having the following data 12345aaaaaaaaaabbbbbbbbbb 12365sssssssssscccccccccc 12365sssss 12367ddddddddddvvvvvvvvvv 12367 vvvvv Here the first column is length 5 second is length 10 third is length 10 if the second or third column exceeds... (3 Replies)
Discussion started by: Brado
3 Replies

2. Shell Programming and Scripting

Merge two file data together based on specific pattern match

My input: File_1: 2000_t g1110.b1 abb.1 2001_t g1111.b1 abb.2 abb.2 g1112.b1 abb.3 2002_t . . File_2: 2000_t Ali england 135 abb.1 Zoe british 150 2001_t Ali england 305 g1111.b1 Lucy russia 126 (6 Replies)
Discussion started by: patrick87
6 Replies

3. Shell Programming and Scripting

Merge lines from one file if pattern matches

I have one comma separated file (a.txt) with two or more records all matching except for the last column. I would like to merge all matching lines into one and consolidate the last column, separated by ":". Does anyone know of a way to do this easily? I've searched the forum but most talked... (6 Replies)
Discussion started by: giannicello
6 Replies

4. UNIX for Dummies Questions & Answers

merge lines within a file that start with a similar pattern

Hello! i have a text file.. which contains the data as follows i want to merge the declarations lines pertaining to one datatype in to a single line as follows i've searched the forum for help.. but couldn't find much help.. how can i do this?? (1 Reply)
Discussion started by: a_ba
1 Replies

5. UNIX for Dummies Questions & Answers

print multiple lines from text file based on pattern list

I have a text file with a list of items/patterns: ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig12238 ConsensusfromCGX_alldays_trimmedcollapsedfilteredreadscontiglist(229095contigs)contig34624... (1 Reply)
Discussion started by: Oyster
1 Replies

6. Shell Programming and Scripting

Merge file lines based off of keyword

Hello Everyone, I have two files I created in a format similar to the ones found below (character position is important): File 1: 21 Cat Y N S Y Y N N FOUR LEGS TAIL WHISKERS 30 Dog N N 1 Y Y N N FOUR LEGS TAIL 33 Fish Y N 1 Y Y N N FINS 43 CAR Y N S Y Y N N WHEELS DOORS... (7 Replies)
Discussion started by: jl487
7 Replies

7. Shell Programming and Scripting

How to merge lines based off of text?

Hello Everyone, I have two files, similar to the following: File 1: 8010 ITEM01 CODE1 FLAG1 filler filler 7020 OBJECT CODE2 FLAG2 filler 6010 THING1 CODE4 FLAG4 6011 ITEM20 CODE7 FLAG7 File 2 contains: 6020 ITEM01 CODEA FLAGA filler filler filler 7000 OBJECT CODEB... (2 Replies)
Discussion started by: jl487
2 Replies

8. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

9. Shell Programming and Scripting

Need to merge lines based on pattern

Hi, I have a requirement to merge multiple lines based on search pattern. The search criteria is : it will search for CONSTRAINT and when it found CONSTRAINT, it will merge all lines to 1 line till it founds blank line. For Example: CREATE TABLE "AMS_DISTRIBUTOR_XREF" ( "SOURCE"... (5 Replies)
Discussion started by: satyaatcgi
5 Replies

10. Shell Programming and Scripting

Help with order lines from a file based on a pattern

Hi I need to order these lines from a txt file my file looks like this IMSI ........................ 1234567890 APN ......................... INTERNET.COM APN ......................... MMS.COM APN ......................... WAP.COM APN ......................... BA.COM IMSI... (4 Replies)
Discussion started by: alone77
4 Replies
HTML::Microformats::Format::XOXO(3pm)			User Contributed Perl Documentation		     HTML::Microformats::Format::XOXO(3pm)

NAME
HTML::Microformats::Format::XOXO - the XOXO microformat SYNOPSIS
use HTML::Microformats::DocumentContext; use HTML::Microformats::Format::XOXO; my $context = HTML::Microformats::DocumentContext->new($dom, $uri); my @objects = HTML::Microformats::Format::XOXO->extract_all( $dom->documentElement, $context); my $list = $objects[0]; # Let's assume this structure: # # <ol class="xoxo people"> # <li> # <a href="http://tobyinkster.co.uk/">Toby Inkster</a> # <dl> # <dt>Eye colour</dt> # <dd>Blue</dt> # <dt>Hair colour</dt> # <dd>Blonde</dt> # <dd>Brown</dt> # </dl> # </li> # </ol> print $list->data->as_array->[0]->get_link_title; # Toby Inkster print $list->data->as_array->[0]->get_properties ->get_value('Eye colour')->[0]; # Blue print join '-', $list->data->as_array->[0] ->get_value('Hair colour'); # Blonde-Brown DESCRIPTION
HTML::Microformats::Format::XOXO inherits from HTML::Microformats::Format. See the base class definition for a description of property getter/setter methods, constructors, etc. Unlike most of the modules in the HTML::Microformats suite, the "data" method returns an HTML::Microformats::Format::XOXO::UL, HTML::Microformats::Format::XOXO::OL or HTML::Microformats::Format::XOXO::DL object, rather than a plain hashref. HTML::Microformats::Format::XOXO::DL Represents an HTML DL element. "$dl->get_values($key)" Treating a DL as a key-value structure, returns a list of values for a given key. Each value is an HTML::Microformats::Format::XOXO::DD object. "$dl->as_hash" Returns a hash of keys pointing to arrayrefs of values, where each value is an HTML::Microformats::Format::XOXO::DD object. "$dl->as_array" Logically what you think get_values("*") might do. HTML::Microformats::Format::XOXO::UL Represents an HTML UL element. "$ul->as_array" Returns an array of values, where each is a HTML::Microformats::Format::XOXO::LI object. HTML::Microformats::Format::XOXO::OL Represents an HTML OL element. "$ol->as_array" Returns an array of values, where each is a HTML::Microformats::Format::XOXO::LI object. HTML::Microformats::Format::XOXO::LI Represents an HTML LI element. "$li->get_link_href" Returns the URL linked to by the first link found within the item. "$li->get_link_rel" Returns the value of the rel attribute of the first link found within the item. This is an unparsed string. "$li->get_link_type" Returns the value of the type attribute of the first link found within the item. This is an unparsed string. "$li->get_link_title" Returns the value of the rel attribute of the first link found within the item if present; the link text otherwise. "$li->get_text" Returns the value of the text in the LI element except for the first DL element within the LI, and the first UL or OL element. "$li->get_html" Returns the HTML code in the LI element except for the first DL element within the LI, and the first UL or OL element. "$li->get_properties" Returns an HTML::Microformats::Format::XOXO::DL object representing the first DL element within the LI. "$li->get_children" Returns an HTML::Microformats::Format::XOXO::OL or HTML::Microformats::Format::XOXO::UL object representing the first OL or UL element within the LI. "$li->get_value($key)" A shortcut for "$li->get_properties->get_values($key)". HTML::Microformats::Format::XOXO::DD This has an identical interface to HTML::Microformats::Format::XOXO::LI. MICROFORMAT
HTML::Microformats::Format::XOXO supports XOXO as described at <http://microformats.org/wiki/xoxo>. RDF OUTPUT
XOXO does not map especially naturally to RDF, so this module returns the data as a JSON literal using the property <http://open.vocab.org/terms/json>. BUGS
Please report any bugs to <http://rt.cpan.org/>. SEE ALSO
HTML::Microformats::Format, HTML::Microformats. AUTHOR
Toby Inkster <tobyink@cpan.org>. COPYRIGHT
Copyright 2008-2011 Toby Inkster This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. DISCLAIMER OF WARRANTIES
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. perl v5.14.2 2011-12-06 HTML::Microformats::Format::XOXO(3pm)
All times are GMT -4. The time now is 08:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy