Concatenate rows and redefine range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Concatenate rows and redefine range
# 8  
Old 06-05-2015
What about 27.30, then? I'd prefer the int($5) way.

---------- Post updated at 12:18 ---------- Previous update was at 12:16 ----------

Quote:
Originally Posted by Scrutinizer
.
.
.
Code:
15 30  26  26  30.0  30.0
15 30  27  27  31.0  31.0
17 32 155 155 325.0 325.0

would need to be combined to :
Code:
15 30  26  155  30.0  325.0

Wasn't the first condition $1 and $2 be the key?
This User Gave Thanks to RudiC For This Post:
# 9  
Old 06-05-2015
Thank you for the useful ideas, will put them in practice.
# 10  
Old 06-06-2015
Sorry to bump up to this post again, but I need your help.
Looping to the files I have I noticed that I might have some lines where fields $5 and $6 are not consecutive. Eg:

Code:
15 30  21  21  25.00  25.00
15 30  22  22  26.00  26.00
15 30  23  23  27.00  27.00
15 30  24  24  28.05  28.05
15 30  25  25  29.07  29.07
15 30  26  26  30.00  30.00
15 30  27  27  31.00  31.00
17 32 155 155 325.00 325.00
17 32 156 156 326.03 326.03
17 32 157 157 423.00 423.00
17 32 158 158 424.00 424.00
17 32 159 159 425.00 425.00
17 32 160 160 428.00 428.00
17 32 161 161 429.00 429.00

Desired output should be:

Code:
15 30 21 23 25.00 27.00
15 30 24 24 28.05 28.05
15 30 25 25 29.07 29.07
15 30 26 27 30.00 31.00
17 32 155 155 325.00 325.00
17 32 156 156 326.03 326.03
17 32 157 159 423.00 425.00
17 32 160 161 428.00 429.00

Poor man attempts were from to edit Chubler_XL script as follow:

Code:
awk 'key {
    if (key == $1" "$2 && f5 ~ ".0$" && $5 ~ ".0$") {
        t3=$3
        t5=$6
        next
    }
    print key,f3,t3,f5,t5
}
{ key=$1" "$2; f3=t3=$3; f5=t5=$6 }
END { if(key) print key,f3,t3,f5,t5 } ' infile

But this didn't worked.

Hope you'll be able to guide me this time as well.

Thanks in advance
# 11  
Old 06-07-2015
Building on top of Chubbier_XL's code and incorporating MadeInGermany's suggestion:
Code:
awk '
NR > 1 {if (key == ($1 " " $2) && t5 == int(t5) && $5 == int($5) && 
	    (t5 + 1) == $5) {
		t3 = $3
		t5 = $5
		next
	}
	print key, f3, t3, f5, t5
}
{	key = $1 " " $2
	f3 = t3 = $3
	f5 = t5 = $5
}
END {	if(NR) print key, f3, t3, f5, t5
}' file

seems to do what you want.

As always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
This User Gave Thanks to Don Cragun For This Post:
# 12  
Old 06-07-2015
Thank you very much, your solution worked fine.

Best Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concatenate broken rows

I need to concatenate the rows that are broken (because of carriage return and line feed) in unix. Input 123|456|789|"" 987|786|"GRT "|"" 3455|896|654|456|"" 457|234|"RT"|"PR TY"|"" Output 123|456|789|"" 987|786|"GRT"|"" 3455|896|654|456|"" 457|234|"RT"|"PRTY"|"" (16 Replies)
Discussion started by: meet_calramz
16 Replies

2. Shell Programming and Scripting

Printing rows based on column range

Hello, I have a file with nearly 57K lines. I want to filter the lines based on the range of values in a column. For e.g. print lines whose 3rd filed is >=0.02. Input file: LOC_Os09g32030 LOC_Os02g18880 0.0200037219149773 undirected NA NA LOC_Os03g58630 LOC_Os09g35690 ... (1 Reply)
Discussion started by: Sanchari
1 Replies

3. Shell Programming and Scripting

Sum of range of rows and columns in matrix

Hi all, I have a large matrix of 720 x 25. I want to get sum of range of rows and columns. Like, I need sum of all columns and row number 2 to 21, then leaving 22nd row, again sum of all columns and row number 23 to 42 again leaving 43rd row and then sum of 44th to 63. Means I want to add all... (4 Replies)
Discussion started by: CAch
4 Replies

4. Shell Programming and Scripting

Need help to read rows from one file and concatenate to another

Hi guys; TBH I am an absolute novice, when it comes to scripting; I do have an idea of the basic commands... Here is my problem; I have a flatfile 'A' containing a single column with multiple rows. I have to create a script which will use 'A' as input and then output a string in in the... (6 Replies)
Discussion started by: carlos_anubis
6 Replies

5. UNIX for Dummies Questions & Answers

Read rows from source file and concatenate output

Hi guys; TBH I am an absolute novice, when it comes to scripting; I do have an idea of the basic commands... Here is my problem; I have a flatfile 'A' containing a single column with multiple rows. I have to create a script which will use 'A' as input and then output a string in in the... (0 Replies)
Discussion started by: carlos_anubis
0 Replies

6. Shell Programming and Scripting

delete rows between closest pattern or range

Hi I am having some problom deleting the lines between two specific lines in a file. need to delete lines between two closest lines. i.e need to find the closest range or pattern in a file with repeating patterns. Sample Input: WARNING <some text in n number of lines> ERROR:2597... (10 Replies)
Discussion started by: sudheer1984
10 Replies

7. Shell Programming and Scripting

Concatenate some of the rows...

i have a file as below and i need to load it into oracle. The problem is, some of the rows are in 2 lines. 123456_PosWlist ----- ----- IN 0/0 123456_PosWListRpt ----- ----- IN 0/0 123456_PosWListCSV ----- -----... (7 Replies)
Discussion started by: Amit.Sagpariya
7 Replies

8. Shell Programming and Scripting

concatenate two files with different No of rows

need a shell which perform following function file 1 ( every time new data comes) 1212 2323 3434 4545 5656 . . . . file 2 (fixed line) update bc_tbl set aix=data , bix=back where cix=U and serial=; now when i execute shell it will concatinate file 1, file 2 & make file 3 as... (3 Replies)
Discussion started by: The_Archer
3 Replies

9. Shell Programming and Scripting

Concatenate rows in to 2 files

I have 2 files FILEA 1232342 1232342 2344767 4576823 2325642 FILEB 3472328 2347248 1237123 1232344 8787890 I want the output to go into a 3rd file and look like: FILEC 1232342 3472328 (1 Reply)
Discussion started by: unxusr123
1 Replies

10. Shell Programming and Scripting

Concatenate 2 rows into 1 row

I need to search a file for two values (valueA & valueB). ValueA will be on a different row than valueB, and concatenate the two together on the same row of my output. Example: search input file for strings "node" and "OS", combine the two results into one row input node A text text OS... (4 Replies)
Discussion started by: indianadoug
4 Replies
Login or Register to Ask a Question