join 2 lines based on 1st field


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers join 2 lines based on 1st field
# 1  
Old 07-29-2012
join 2 lines based on 1st field

hi
i have a file with the following lines


Code:
 
2303:13593:137135 16 abc1 26213806.......
1234:45675:123456 16 bbc1 9813806.......
2303:13593:137135 17 bna1 26566444....
1234:45675:123456 18 nnb1 98123456.......

i want to join the lines having common 1st field i,e.,

Code:
 
2303:13593:137135 16 abc1 26213806.......2303:13593:137135 17 bna1 26566444....

Code:
 
sed 'N;s/\n/ /'

would join lines how to specify my condition? the field that has to be compared is the first field i,e .,
Code:
number:number:number

# 2  
Old 07-29-2012
Try this, test being the input file:
Code:
 sort -t\: test|paste -sd' \n' -

resulting in
Code:
1234:45675:123456 16 bbc1 9813806....... 1234:45675:123456 18 nnb1 98123456.......
2303:13593:137135 16 abc1 26213806....... 2303:13593:137135 17 bna1 26566444....

These 2 Users Gave Thanks to RudiC For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join columns across multiple lines in a Text based on common column using BASH

Hello, I have a file with 2 columns ( tableName , ColumnName) delimited by a Pipe like below . File is sorted by ColumnName. Table1|Column1 Table2|Column1 Table5|Column1 Table3|Column2 Table2|Column2 Table4|Column3 Table2|Column3 Table2|Column4 Table5|Column4 Table2|Column5 From... (6 Replies)
Discussion started by: nv186000
6 Replies

2. UNIX for Beginners Questions & Answers

Print lines based upon unique values in Nth field

For some reason I am having difficulty performing what should be a fairly easy task. I would like to print lines of a file that have a unique value in the first field. For example, I have a large data-set with the following excerpt: PS003,001 MZMWR/ L-DWD// * PS003,001... (4 Replies)
Discussion started by: jvoot
4 Replies

3. Shell Programming and Scripting

awk join lines based on keyword

Hello , I will need your help once again. I have the following file: cat file02.txt PATTERN XXX.YYY.ZZZ. 500 ROW01 aaa. 300 XS 14 ROW 45 29 AS XD.FD. PATTERN 500 ZZYN002 ROW gdf gsste ALT 267 fhhfe.ddgdg. PATTERN ERE.MAY. 280 PATTERRNTH 5000 rt.rt. ROW SO a 678 PATTERN... (2 Replies)
Discussion started by: alex2005
2 Replies

4. Shell Programming and Scripting

Concatenation lines based on first field of the lines

Hello All, This is to request some assistance on the issue that I encountered until recently. Problem is: I have a pipe delimited file in which some lines/records are broken. Now, I have to join/concatenate broken lines in the file to form actual record to make sure that the count of records... (8 Replies)
Discussion started by: svks1985
8 Replies

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

6. Shell Programming and Scripting

Combine multiple lines in file based on specific field

Hi, I have an issue to combine multiple lines of a file. I have records as below. Fields are delimited by TAB. Each lines are ending with a new line char (\n) Input -------- ABC 123456 abcde 987 890456 7890 xyz ght gtuv ABC 5tyin 1234 789 ghty kuio ABC ghty jind 1234 678 ght ... (8 Replies)
Discussion started by: ratheesh2011
8 Replies

7. Shell Programming and Scripting

Remove duplicate lines based on field and sort

I have a csv file that I would like to remove duplicate lines based on field 1 and sort. I don't care about any of the other fields but I still wanna keep there data intact. I was thinking I could do something like this but I have no idea how to print the full line with this. Please show any method... (8 Replies)
Discussion started by: cokedude
8 Replies

8. Shell Programming and Scripting

join based on line number when one file is missing lines

I have a file that contains 87 lines, each with a set of coordinates (x & y). This file looks like: 1 200.3 -0.3 2 201.7 -0.32 ... 87 200.2 -0.314 I have another file which contains data that was taken at certain of these 87 positions. i.e.: 37 125 42 175 86 142 where the first... (1 Reply)
Discussion started by: jackiev
1 Replies

9. Shell Programming and Scripting

join files based on a common field

Hi experts, Would you please help me with this? I have several files and I need to join the forth field of them based on the common first field. here's an example... first file: 280346 39.88 -75.08 547.8 280690 39.23 -74.83 538.7 280729 40.83 -75.08 499.2 280907 40.9 -74.4 507.8... (5 Replies)
Discussion started by: GoldenFire
5 Replies

10. Shell Programming and Scripting

add lines automatically based on a field on another file

hello I have a number of lines that need to be added at the end of a file each time I add a field in another file (let's name it file2) file2 has this format: filed1:field2:path1:path2:path3:path... Whenever I add a path field, I should add to file1 these lines: <Location path1>... (0 Replies)
Discussion started by: melanie_pfefer
0 Replies
Login or Register to Ask a Question