awk or python to join alternating columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk or python to join alternating columns
# 1  
Old 10-14-2009
awk or python to join alternating columns

Hi,
here is my input
Code:
TEST-SAM-A6ZZ SM-S6KV 0 0 2 1 2 3 3 3 2 2 2 2 1 1 2 2 1 3 1 3
1361 SM-HA4Q 0 0 2 1 3 3 3 3 2 2 2 2 1 1 2 2 1 3 3 3 4 2 4 2 2
276217 SM-H9ZG 0 0 2 2 3 3 3 3 2 2 2 2 1 1 2 2 3 3 1 3 2 2 2 2
GC15458 SM-HAQX 0 0 2 1 2 3 1 3 2 2 2 2 1 1 2 2 1 3 1 3 2 2 2
18331 SM-HA5E 0 0 2 2 2 3 1 3 2 2 2 2 1 1 2 2 1 3 3 3 2 2 2 2
TEST-SAM-AN7H SM-MGFV 0 0 2 2 3 3 3 3 2 2 2 2 1 1 2 2 1 3 1 3
TEST-SAM-AGRV SM-HB4V 0 0 2 1 2 3 3 3 2 2 2 2 1 1 2 2 1 3 1 3
TEST-SAM-A7P5 SM-S6PE 0 0 2 2 2 2 1 1 2 2 2 2 1 1 2 2 3 3 3 3
TEST-SAM-A6MQ SM-S6NR 0 0 2 2 2 3 1 3 2 2 2 2 1 1 2 2 3 3 3 3
TEST-SAM-A6LP SM-S6MQ 0 0 2 1 3 3 3 3 2 2 2 2 4 1 4 2 1 3 1 3

Output needs to join two columns each starting at col 7 till end of line.
Code:
TEST-SAM-A6ZZ SM-S6KV 0 0 2 1 23 33 22 22 11 22 13 13
1361 SM-HA4Q 0 0 2 1 33 33 22 22 11 22 13 33 42 42 2
276217 SM-H9ZG 0 0 2 2 33 33 22 22 11 22 33 13 22 22
GC15458 SM-HAQX 0 0 2 1 23 13 22 22 11 22 13 13 22 2
18331 SM-HA5E 0 0 2 2 23 13 22 22 11 22 13 33 22 22
TEST-SAM-AN7H SM-MGFV 0 0 2 2 33 33 22 22 11 22 13 13
TEST-SAM-AGRV SM-HB4V 0 0 2 1 23 33 22 22 11 22 13 13
TEST-SAM-A7P5 SM-S6PE 0 0 2 2 22 11 22 22 11 22 33 33
TEST-SAM-A6MQ SM-S6NR 0 0 2 2 23 13 22 22 11 22 33 33
TEST-SAM-A6LP SM-S6MQ 0 0 2 1 33 33 22 22 41 42 13 13

Thank you very much for your help
# 2  
Old 10-14-2009
nawk -f gene.awk myFile

gene.awk:
Code:
{
  for(i=7; i<=NF;i+=2){
    $i=$i $(i+1)
    $(i+1)=""
  }
  gsub(FS FS, FS)
  print
}

# 3  
Old 10-14-2009
I don't know how you do it.
But you are simply brilliant!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join, merge, fill NULL the void columns of multiples files like sql "LEFT JOIN" by using awk

Hello, This post is already here but want to do this with another way Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: 1|123|jojo 1|NULL|bibi... (2 Replies)
Discussion started by: yjacknewton
2 Replies

2. Shell Programming and Scripting

Join two files combining multiple columns and produce mix and match output

I would like to join two files when two columns in each file matches with each other and then produce an output when taking multiple columns. Like I have file A 1234,ABCD,23,JOHN,NJ,USA 2345,ABCD,24,SAM,NY,USA 5678,GHIJ,24,TOM,NY,USA 5678,WXYZ,27,MAT,NJ,USA and file B ... (2 Replies)
Discussion started by: mady135
2 Replies

3. Shell Programming and Scripting

Join two lines into one, but the second line only the last two columns

Hi guys, I hope you are doing well! I have a file and I need to join two lines into one, but the second line I need only the last two columns. ================= "eHealth Trend Report","logoRpt" "LAN/WAN Group 123" "Divide by Time" "switch1_a-RH-Serial0" "BW: 1.02 M" ... (4 Replies)
Discussion started by: antoniorajr
4 Replies

4. Shell Programming and Scripting

Join two files with matching columns

Hi, I need to join two files together with one common value in a column. I think I can use awk or join or a combination but I can't quite get it. Basically my data looks like this, with the TICKER columns matching up in each file File1 TICKER,column 1, column, 2, column, 3, column 4 ... (6 Replies)
Discussion started by: unkleruckus
6 Replies

5. Shell Programming and Scripting

Sort and join multiple columns using awk

Is it possible to join all the values after sorting them based on 1st column key and replace empty rows with 0 like below ? input a1 0 a1 1 a1 1 a3 1 b2 1 a2 1 a4 1 a2 1 a4 1 c4 1 a3 1 d1 1 a3 1 b1 1 d1 1 a4 1 c4 1 b2 1 b1 1 b2 1 c4 1 d1 1 output... (8 Replies)
Discussion started by: quincyjones
8 Replies

6. Shell Programming and Scripting

Join 4 files on first three columns

Hi, Can someone suggest me on how to join 4 files by comparing the first three columns? ---------- Post updated at 03:56 PM ---------- Previous update was at 03:42 PM ---------- Hope it helps someone. I was looking online for a solution and on stackoverflow, I found a solution and tried... (6 Replies)
Discussion started by: jacobs.smith
6 Replies

7. UNIX for Dummies Questions & Answers

moving columns to alternating rows

Hello, I have a space delimited file like this: AAA BBB CCC DDD EEE FFF GGG HHH III And I would like to change it to the following (including the plus signs): AAA BBB + CCC DDD EEE + FFF GGG HHH (2 Replies)
Discussion started by: blakers
2 Replies

8. Shell Programming and Scripting

awk command for simple join command but based on 2 columns

input1 a_a a/a 10 100 a1 a_a 20 200 b1 b_b 30 300 input2 a_a a/a xxx yyy a1 a1 lll ppp b1 b_b kkk ooo output a_a a/a 10 100 xxx yyy (2 Replies)
Discussion started by: ruby_sgp
2 Replies

9. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

10. Shell Programming and Scripting

Join columns from 2 files

Hello guys. I need to join columns of Start Time and End time of 2 files. The Examples is: File 1 APPLICATION GROUP_NAME JOB_NAME ODATE STATUS START_TIME END_TIME :: MODCMPDA EDPONLINE MC00A1700 071102 Ended OK 20071102 17:00:01 File 2 APPLICATION GROUP_NAME JOB_NAME ODATE... (2 Replies)
Discussion started by: osramos
2 Replies
Login or Register to Ask a Question