Merging fields --- Help me plz


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merging fields --- Help me plz
# 1  
Old 01-18-2009
Merging fields --- Help me plz

INPUT

have a file with 2 columns. evry set in a column ends with a symbol //.
the first one with something like chr, chr no, chromosome name, cell no. cell no. etc and the second column has values belong to the first columnlike chr Xy, 22, 345,22222 etc. Some clumns have repeated but not duplicate values. with these I want to make file with first cloumn as first row and second olumn as second row and so on...

chr chrXY
chr no 22
chrname FUUR
Cell 224Neuron
Cell no 22222

//

chr chrYY
chr no 23
chrname FUUS
Cell 225Neuron
Cell no 22223

//

chr chrYY
chr no 24
chrname FUUT
Cell 226Neuron
Cell no 22222
Cell 227Neuron
Cell no 222245
Cell 230Neuron
Cell no 22245
//

chr chrYY
chr no 25
chrname RUUS
Cell 225Neuron
Cell no 52223

OUTPUT

hr .........chr no....... chrname ......Cell............. Cell no

chrXY....... 22 ............FUUR .........224Neuron..... 22222
chrYY .......23 .............FUUS .........225Neuron .....22223
chrYY....... 24 .............FUUT.......... 226Neuron.... 222222
...................................................227Neuron.... 222245
..................................................230Neuron ......22245
chrYY .......25............. RUUS ..........225Neuron ......52223
# 2  
Old 01-22-2009
Try this:

Code:
awk '
        BEGIN { printf("%8s %8s %8s %10s %8s\n","chr","chrno","chrname","cell","cellno") }
        /^chr no/ { chrno=$3; next }
        /^chr / { chr=$2; next }
        /^chrname / { chrname=$2; next }
        /^Cell no / {
                cellno=$3
                printf("%8s %8s %8s %10s %8s\n",chr,chrno,chrname,cell,cellno)
                chr=chrno=chrname=cell=cellno=""
                next
        }
        /^Cell / { cell=$2; next }
' inputfile

# 3  
Old 01-22-2009
hi

Thanx alot for the reply and tour valuble time
but i have a huge file and these are the som of the lines i have extarcted from the data base.
I think the same code is not apllicable to the whole databse rt.
And most importantly the list is not in the order.
# 4  
Old 01-22-2009
????

If you ask an incomplete question, you will get an incomplete answer. The output of my solution is almost exactly what you described, and in the same order:

Code:
     chr    chrno  chrname       cell   cellno
   chrXY       22     FUUR  224Neuron    22222
   chrYY       23     FUUS  225Neuron    22223
   chrYY       24     FUUT  226Neuron    22222
                            227Neuron   222245
                            230Neuron    22245
   chrYY       25     RUUS  225Neuron    52223

# 5  
Old 01-22-2009
hey

hey sorry da if u find it hard
may b my mistake. I will try to post clearly. but the data is huge and i'm unable to make i tprecise.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Shell Programming and Scripting

Merging fields in CSV

Hi experts, I have a csv file which has one field (ID) repeated multiple times with corresponding other field values. I need to convert this file in a format where for a ID all other values has to be present in single field. For Eg : Here in below file ID 1 is repeated 3 times with different... (7 Replies)
Discussion started by: bharathbangalor
7 Replies

3. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

4. Shell Programming and Scripting

Matching and Merging csv data fields based on a common field

Dear List, I have a file of csv data which has a different line per compliance check per host. I do not want any omissions from this csv data file which looks like this: date,hostname,status,color,check 02-03-2012,COMP1,FAIL,Yellow,auth_pass_change... (3 Replies)
Discussion started by: landossa
3 Replies

5. Shell Programming and Scripting

Merging CSV fields based on a common field

Hi List, I have two files. File1 contains all of the data I require to be processed, and I need to add another field to this data by matching a common field in File2 and appending a corresponding field to the data in File1 based on the match... So: File 1:... (1 Reply)
Discussion started by: landossa
1 Replies

6. Shell Programming and Scripting

Merging two files by comparing three fields

Hi Experts, I need your timely help. I have a problem with merging two files. Here my situation : Here I have to compare first three fields from FILE1 with FILE2. If they are equal, I have to append the remaining values from FILE2 with FILE1 to create the output. FILE1: Class ... (3 Replies)
Discussion started by: Hunter85
3 Replies

7. Shell Programming and Scripting

Merging fields --- Join is not working

Hi GUYS sorry for putting simple query. I have tried the methods posted previously in this site but I'm unable to join the similar values in different columns of different files. I used sort -u file1 and join but no use.?? I'm attaching my inputfiles.Plz chek them I have two files. 1st file... (10 Replies)
Discussion started by: repinementer
10 Replies

8. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

9. Shell Programming and Scripting

merging fields from 2 different files.

File 1 3337304 2 4 DH.ER@TORONTO.CA 20080504 04622 3337305 2 4 A@C.COM 20080504 04622 3337306 2 4 JO@NET.NET 20080504 04622 3337307 2 4 L@GMAIL.COM 20080504 05344 2479201 2 2 ORY@YAHOO.COM 20080504 05344 File 2 ... (5 Replies)
Discussion started by: rudoraj
5 Replies

10. UNIX for Dummies Questions & Answers

plz Help How should I configure cc compiler output file plz help???

i.e configuration of C compiler :confused: (4 Replies)
Discussion started by: atiato
4 Replies
Login or Register to Ask a Question