Parse and reformat


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse and reformat
# 1  
Old 10-25-2014
Parse and reformat

Trying to parse column C ($3) of the attached file (104 rows). The data is in the below format all in a string. Each string would be a separate row with the data in column A ($1) and column B ($2) being the header. All the data is in seperate columns as well. Thank you Smilie.

Code:
 ACTA 59 A_16_P32713632=chr10:90695750-90695810, A_16_P32713635=chr10:90696573-90696633, A_16_P32713680=chr10:90697419-90697479

Code:
 ADAMTS10 7 A_16_P41135847=chr19:8647429-8647489, A_16_P03421012=chr19:8659282-8659342


Desired Output:
Code:
 
ACTA2	59
A_16_P32713632     chr10     90695750     90695810
A_16_P32713635     chr10     90696573     90696633
A_16_P32713680     chr10     90697419     90697479

Code:
 
ADAMTS10	7
A_16_P41135847     chr19     8647429     8647489
A_16_P03421012     chr19     8659282     8659342,

# 2  
Old 10-25-2014
Code:
awk '{print $1,$2;for(i=3;i<=NF;i++){ gsub(/[=:-]/,OFS,$i); sub(/,/,"",$i); print $i }}' OFS='\t' file

This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 10-25-2014
Like this:
Code:
awk     '       {print $1, $2
                 for (i=3; i<=NF; i++)
                        {n=split ($i, T, "[=:-,]")
                         print T[1],T[2],T[3],T[4]
                        }
                }
        ' OFS="\t" file
ACTA    59
A_16_P32713632    chr10    90695750    90695810
A_16_P32713635    chr10    90696573    90696633
A_16_P32713680    chr10    90697419    90697479
ADAMTS10    7
A_16_P41135847    chr19    8647429    8647489
A_16_P03421012    chr19    8659282    8659342

This User Gave Thanks to RudiC For This Post:
# 4  
Old 10-25-2014
Thank you Smilie., works perfect!
# 5  
Old 10-25-2014
Or something like this

Code:
awk '{match($0,/^[^ ]* [^ ]* /);s=substr($0,RLENGTH+1); gsub(/[=:-]/,OFS,s); gsub(/, /,RS,s); $0 = $1 OFS $2 RS s}1' file

# 6  
Old 10-25-2014
Can the code be modified to output this:

same data just no header.

Desired Output:

Code:
A_16_P32713632     chr10     90695750     90695810
A_16_P32713635     chr10     90696573     90696633
A_16_P32713680     chr10     90697419     90697479

Code:
A_16_P41135847     chr19     8647429     8647489
A_16_P03421012     chr19     8659282     8659342

Thank you Smilie.
# 7  
Old 10-25-2014
remove print $1,$2;

Code:
awk '{for(i=3;i<=NF;i++){ gsub(/[=:-]/,OFS,$i); sub(/,/,"",$i); print $i }}' OFS='\t' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reformat awk output

I need to rearrange the output but i am unable to arrange it to match the format. In the output i need NAME=\"To in the column . Bash: #!/bin/bash cd /cygdrive/c/output/a cat *.txt > output.txt i=/cygdrive/c/output/a/output.csv #echo "NE_Name, Source, Destination, OSPF_AREA_ID"... (4 Replies)
Discussion started by: adgjmpt
4 Replies

2. Shell Programming and Scripting

Help with reformat data set

Input file 4CL1 O24145 CoA1 4CL1 P31684 CoA1 4CL1 Q54P77 CoA_1 73 O36421 Unknown 4CL3 Q9S777 coumarate 4CL3 Q54P79 coumarate 4CL3 QP7932 coumarate Desired output result 4CL1 O24145#P31684 CoA1 4CL1 Q54P77 CoA_1 73 O36421 Unknown 4CL3 Q9S777#Q54P79#QP7932 coumarate I... (5 Replies)
Discussion started by: perl_beginner
5 Replies

3. Shell Programming and Scripting

Help with reformat data structure

Input file: bv|111259484|pir||T49736_real_data bv|159484|pir||T9736_data_figure bv|113584|prf|T4736|truth bv|113584|pir||T4736_truth Desired output: bv|111259484|pir|T49736|real_data bv|159484|pir|T9736|data_figure bv|113584|prf|T4736|truth bv|113584|pir|T4736|truth Once the... (8 Replies)
Discussion started by: perl_beginner
8 Replies

4. Shell Programming and Scripting

Reformat a file

I have a csv file with 11 columns. The first columns contains the User Id. One User id can have multiple sub Id. The value of Sub Id is in column 10. 100026,captjason@hawaii.rr.com ,jason ,wolford ,1/16/1969, ,US, ,96761 ,15 ,seg_id 100026,captjason@hawaii.rr.com ,jason ,wolford ,1/16/1969,... (3 Replies)
Discussion started by: r_t_1601
3 Replies

5. Shell Programming and Scripting

Please help me reformat this file

I am working with a file of the form; 4256 7726 1 6525 716 1 7626 0838 1 8726 7623 2 8625 1563 2 1662 2628 3 1551 3552 3 1542 7984 ... (3 Replies)
Discussion started by: digipak
3 Replies

6. UNIX for Advanced & Expert Users

reformat ps output

I often use "ps -ef" command to list all running processes. Now i want to customize the output to show only 2 parts: CMD and UID as below: /bin/bash /usr/bin/run-parts /etc/cron.weekly root /usr/sbin/httpd apache /usr/sbin/httpd apache /usr/sbin/httpd apache I use ps -ef | awk '{print $8"... (3 Replies)
Discussion started by: fongthai
3 Replies

7. Solaris

how to reformat a hard disk

hi i need help on how to reformat a hard disk. what should i do since i don't have any bootable disk. i'm using solaris 1 & 2 and also need to make a backup copy of the current hard disk. appreciate all the help i can get... (14 Replies)
Discussion started by: mr_balodoy
14 Replies

8. Shell Programming and Scripting

Reformat Crontab file

I need help writing a script that will reformat a crontab file. The first thing the script is doing is a crontab -l > crontab.txt. I need the crontab.txt file to read "8.00 PM every weekday (Mon-Fri) only in Oct." instead of the orig format "0 20 * 10 1-5" (1 Reply)
Discussion started by: alnita
1 Replies

9. UNIX for Dummies Questions & Answers

Date Reformat

Hello, I have a .CSV file with 10+ datetime columns. The way the data is stored in these columns are - 4/4/2006 3:45:30 PM I want the single digits to be left padded with a zero so the above looks like 04/04/2006 03:45:30 PM As the dates and times are different throughout the file... (2 Replies)
Discussion started by: F-1
2 Replies

10. Shell Programming and Scripting

reformat the file

Hi all, I ran into this problem, hope you can help I have a text file like this: Spriden ID First Name Last Name Term Code Detail Code Amount Trans Date Description ... (3 Replies)
Discussion started by: CamTu
3 Replies
Login or Register to Ask a Question