Parse and reformat


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse and reformat
# 8  
Old 10-25-2014
How is the order of the output determined in the script?

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

For example, if instead of:
Code:
A_16_P32713632     chr10     90695750     90695810
A_16_P32713635     chr10     90696573     90696633
A_16_P32713680     chr10     90697419     90697479

a different out is needed:

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

Same data just different order.

Thank you Smilie.
# 9  
Old 10-25-2014
Quote:
Originally Posted by cmccabe
How is the order of the output determined in the script?

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

For example, if instead of:
Code:
A_16_P32713632     chr10     90695750     90695810
A_16_P32713635     chr10     90696573     90696633
A_16_P32713680     chr10     90697419     90697479

a different out is needed:

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

Same data just different order.

Thank you Smilie.
Read RudiC's answer and change array index https://www.unix.com/302922478-post3.html

print T[1],T[2],T[3],T[4] to print T[2],T[3],T[4],T[1]
# 10  
Old 10-25-2014
Code:
 awk     '               {for (i=3; i<=NF; i++)
                        {n=split ($i, T, "[=:-,]")
                         print T[4],T[1],T[2],T[3]
                        }
                }
        ' OFS="\t" header_sort.txt > sort.txt

like this

Code:
 Sort.txt (no headers)
chr10     90695750     90695810     A_16_P32713632
chr10     90696573     90696633     A_16_P32713635

Thanks Smilie.
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