Sponsored Content
Top Forums Shell Programming and Scripting Join all the lines matching similar pattern Post 302746143 by evrurs on Tuesday 18th of December 2012 11:02:02 PM
Old 12-19-2012
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

Code:
> cat sample.txt
sam 2012/11/23
sam 2012/12/5
sam 2012/12/5
jones 2012/10/16
jones 2012/10/17
jones 2012/10/17
mike 2012/11/24
mike 2012/12/25
mike 2012/12/25
mike 2012/12/25
mike 2012/12/25
mike 2012/12/25

I have tried the following command and however it is joining all the lines. Perhaps, i want to join the lines matching similar pattern.

Code:
> sed -e :a -e '$!N;s/\n'$line'/ '$line'/;ta' -e 'P;D' sample.txt
sam 2012/11/23 sam 2012/12/5 sam 2012/12/5 jones 2012/10/16 jones 2012/10/17 jones 2012/10/17 mike 2012/11/24 mike 2012/12/25 mike 2012/12/25 mike 2012/12/25 mike 2012/12/25 mike 2012/12/25

Thanks in Advance. SmilieSmilieSmilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

counting the lines matching a pattern, in between two pattern, and generate a tab

Hi all, I'm looking for some help. I have a file (very long) that is organized like below: >Cluster 0 0 283nt, >01_FRYJ6ZM12HMXZS... at +/99% 1 279nt, >01_FRYJ6ZM12HN12A... at +/99% 2 281nt, >01_FRYJ6ZM12HM4TS... at +/99% 3 283nt, >01_FRYJ6ZM12HM946... at +/99% 4 279nt,... (4 Replies)
Discussion started by: d.chauliac
4 Replies

2. 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

3. UNIX for Dummies Questions & Answers

Matching and reporting near-similar lines in a file

Hi, I have a file with the lines as below: C_10_A05_T7 C_10_A06_SP6 C_10_B05_SP6 C_10_B05_T7 C_10_B01_SP6 C_10_B01_T7 C_12_G07_SP6 C_12_G11_SP6 C_12_G11_T7 C_2_H18_T7 C_2_I02_SP6 C_2_I02_T7 C_2_I13_SP6 C_2_I17_SP6 The four segments of each line are connected by '_' symbols. I... (7 Replies)
Discussion started by: Fahmida
7 Replies

4. 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

5. Shell Programming and Scripting

Help in unix script to join similar lines of input

Hi, I have been thinking of how to script this but i have no clue at all.. Could someone please help me out or give me some idea on this? I would like to group those lines with the same first variable in each line, joining the 2nd variables with commas. Let's say i have the following input. ... (3 Replies)
Discussion started by: rei125
3 Replies

6. UNIX for Dummies Questions & Answers

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. 20120924|<?xml record 1 line1....record 1 line1....record 1 line1.... record 1 line2....record 1 line2....record 1 line2.... record 1... (3 Replies)
Discussion started by: Dipalik
3 Replies

7. 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

8. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

9. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

10. Shell Programming and Scripting

Fetch lines between 1st and 4th similar pattern

Hi Folks, I have a big file that looks like below ========== kjhjl kjlklkkhcgflj fgf ========== xsww23edc ccdde3rfv ceerfcc vff4 ========== zaq12wsx xsw23edc ========== ========== (3 Replies)
Discussion started by: jayadanabalan
3 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 08:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy