Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Join the lines until next pattern match Post 302708135 by Dipalik on Monday 1st of October 2012 05:59:42 AM
Old 10-01-2012
Join the lines until next pattern match

Hi,

I have a data file where data is splitted into multiple lines. And, each valid record starts with a patten date | <?xml and ends with pattern </dmm>
e.g.
Code:
20120924|<?xml record 1 line1....record 1 line1....record 1 line1....
record 1 line2....record 1 line2....record 1 line2....
record 1 line3....record 1 line3....</dmm>
20120924|<?xml record 2 line1....record 2 line1....record 2 line1....
record 2 line2....record 2 line2....</dmm>
20120924|<?xml record 3 line1....record 3 line1
record 3 line2
record 3 line3....record 3 line3
record 3 line4....record 3 line4....record 3 line4....</dmm>

And, to process this data further i need one record as a single line:

output required:
Code:
20120924|<?xml record 1 line1....record 1 line1....record 1 line1....record 1 line2....record 1 line2....record 1 line2....record 1 line3....record 1 line3....</dmm>
20120924|<?xml record 2 line1....record 2 line1....record 2 line1....record 2 line2....record 2 line2....</dmm>
20120924|<?xml record 3 line1....record 3 line1
record 3 line2record 3 line3....record 3 line3record 3 line4....record 3 line4....record 3 line4....</dmm>


Can someone please help me out to get the desired output.

Thanks
Dipali
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 10-01-2012 at 07:03 AM.. Reason: code tags,please!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

retrieve lines that match a pattern

Hi, I would like to know how can I get lines from a text file that match no more than 2 '>'. Example: Input file: a >cr1 4 a>b b>c a >cr2 5 a>b Output file: a >cr2 5 a>b Thanks in advance (2 Replies)
Discussion started by: fadista
2 Replies

2. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

3. UNIX for Dummies Questions & Answers

sed, join lines that do not match pattern

Hello, Could someone help me with sed. I have searched for solution 5 days allready :wall:, but cant find. Unfortunately my "sed" knowledge not good enough to manage it. I have the text: 123, foo1, bar1, short text1, dat1e, stable_pattern 124, foo2, bar2, long text with few lines, date,... (4 Replies)
Discussion started by: petrasl
4 Replies

4. UNIX for Dummies Questions & Answers

Join lines on finding a pattern

I have a file with the following contents. DTP START START START DTP START DTP START DTP START I like to join the lines like this DTP START START START DTP START DTP START (2 Replies)
Discussion started by: nsuresh316
2 Replies

5. Shell Programming and Scripting

Join all the lines matching similar pattern

I am trying to Join all the lines matching similar pattern. Example ; I wanted to join all the lines which has sam to a single line. In next line, i wanted to have all the lines with jones to a single line....etc > cat sample.txt sam 2012/11/23 sam 2012/12/5 sam 2012/12/5 jones... (2 Replies)
Discussion started by: evrurs
2 Replies

6. Shell Programming and Scripting

Print lines that do not match the pattern

I need to print the lines that do not match a pattern. I tried using grep -v and sed -n '/pattern/!p', but both of them are not working as I am passing the pattern as variable and it can be null some times. Example ........ abcd...... .........abcd...... .........abcd......... (4 Replies)
Discussion started by: sunny1234
4 Replies

7. Shell Programming and Scripting

Join lines from two files based on match

I have two files. File1 >gi|11320906|gb|AF197889.1|_Buchnera_aphidicola ATGAAATTTAAGATAAAAAATAGTATTTT >gi|11320898|gb|AF197885.1|_Buchnera_aphidicola ATGAAATTTAATATAAACAATAAAA >gi|11320894|gb|AF197883.1|_Buchnera_aphidicola ATGAAATTTAATATAAACAATAAAATTTTT File2 AF197885 Uroleucon aeneum... (2 Replies)
Discussion started by: pathunkathunk
2 Replies

8. Shell Programming and Scripting

Printing next 6 lines from of pattern match

Hi, i have a big file having many opcodes. if (opcode="01110000000100000000" ) then --fadd result.opcode := "01110000000100000000"; result.s0 := '1'; result.s1 := '1'; result.s2 := '0'; result.inst := '0'; result.scalar := '1';... (7 Replies)
Discussion started by: twistedpair
7 Replies

9. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

10. UNIX for Beginners Questions & Answers

Sed/awk join lines once pattern found

Hi all OS - RHEL6.4 I have input file -f1.txt I need to search line which starts with \Start and read next line till it gets blank line and join them all. I need to trim any trailing spaces for each line.So output.txt should be.. \Start\now\fine stepwatch this space for toolsends... (7 Replies)
Discussion started by: krsnadasa
7 Replies
RDF::Query::Plan::Join(3pm)				User Contributed Perl Documentation			       RDF::Query::Plan::Join(3pm)

NAME
RDF::Query::Plan::Join - Join query plan base class. VERSION
This document describes RDF::Query::Plan::Join version 2.908. METHODS
Beyond the methods documented below, this class inherits methods from the RDF::Query::Plan class. "new ( $lhs, $rhs, $optional )" "lhs" Returns the left-hand-side plan to the join. "rhs" Returns the right-hand-side plan to the join. "optional" "bf ()" Returns a string representing the state of the nodes of the triple (bound or free). "join_classes" Returns the class names of all available join algorithms. "distinct" Returns true if the pattern is guaranteed to return distinct results. "ordered" Returns true if the pattern is guaranteed to return ordered results. "plan_prototype" Returns a list of scalar identifiers for the type of the content (children) nodes of this plan node. See RDF::Query::Plan for a list of the allowable identifiers. "plan_node_data" Returns the data for this plan node that corresponds to the values described by the signature returned by "plan_prototype". AUTHOR
Gregory Todd Williams <gwilliams@cpan.org> perl v5.14.2 2012-01-31 RDF::Query::Plan::Join(3pm)
All times are GMT -4. The time now is 10:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy