Sponsored Content
Top Forums Shell Programming and Scripting Transpose from row to column using timestamp in first column Post 303021700 by jiam912 on Wednesday 15th of August 2018 05:27:11 AM
Old 08-15-2018
Hi Don

I changed to 6 lines the group, because my input sample changed a little. But always it will fixed to 6 lines the block.

The number of fields a group of lines is a constant. NO. it will be different in some cases.

As i say before the changes can be 6 or maximun 12 when the date does not change after 6 lines.

Sorry if dont aswer exactly your questions.

I figert out the issue using the 2 codes below..

Code:
gawk '
BEGIN{
   FS=OFS=","
}
prev!=$1 && prev{
   for(i=1;i<=count;i++){
     print prev,a[prev,i]
   }
   prev=count=""
}
{
   prev=$1
   sub(/[^,]*,/,"")
   if(count==6){
     count=1
   }
   else{
     count++
   }
   a[prev,count]=a[prev,count]?a[prev,count] OFS $0:$0
}
END{
   if(prev){
     for(i=1;i<=count;i++){
        print prev,a[prev,i]
     }
   }
}'  tmp1.txt > tmp1

gawk -F, '
 func init_block() {ts=$1;delete a;cnt=0;nf0=NF}
 func dump_block() {for(f=2;f<=nf0;f+=1){printf("%s",ts);for(r=1;r<=cnt;r+=1){printf(",%s",a[r,f])};print ""}}
 BEGIN{ts=-1}
 ts<0{init_block()}
 ts!=$1{dump_block();init_block()}
 {cnt+=1;for(f=1; f<=NF; f++) a[cnt,f]=$f}
 END{dump_block()}' < tmp1 > tmp.txt

Using this codes i got exactly the desired output.

I believe you can do the same output using a shot way code.

Thanks for your help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Row to column transpose

Can we transpose rows to columns? Fields within row are separated by a comma. (10 Replies)
Discussion started by: videsh77
10 Replies

2. Shell Programming and Scripting

How do I transpose a column of results to a row

Hi, Can anyone advise me what command I could use to display the results of the following command as a row. Thanks Gareth (6 Replies)
Discussion started by: m223464
6 Replies

3. Shell Programming and Scripting

Transpose column to row

Hi i have a file which has values seperated by "," as shown below and I want to transpose for every doc_id in one row. Input: DOC_ID,KEYWORD 105,REGISTROS 105,GEOLOGIA 105,NUCLEOS 105,EXPEDIENTE 105,PROGRAMAS 10025,EXPEDIENTE 10025,LOCALIZACIONES 10025,OFICIOS 10025,PROGRAMAS... (4 Replies)
Discussion started by: juelillo
4 Replies

4. Shell Programming and Scripting

Row to column transpose between same pattern.

Hi All, I have been trying to transpose rows to column in an large file (about 15000 lines) between matching pattern. Searched all posts in this forum, but not able find the solution to my problem. Any help appreciated.!! Input /*------XXXXXX-------*/ owner: XXXX location: XXXX... (3 Replies)
Discussion started by: RobP
3 Replies

5. UNIX for Dummies Questions & Answers

Row to column transpose

Hi there, Below is sample three rows which i need transpose into multiple rows. By keeping first 2 fields static and split them into multiple rows depend following date field. Each into seperate rows. Sample code: ... (6 Replies)
Discussion started by: ganeshd
6 Replies

6. Shell Programming and Scripting

Column to row Transpose

Hi Folks, Iam a kinda newbie to unix shell scripting, the scenario is i have a text file containing the following info Charlie chicago 15 Charlie newyork 26 jonny chicago 14 jonny newyork 15 joe chicago 15 joe newyork 18output should be Name chicago ... (3 Replies)
Discussion started by: tech_frk
3 Replies

7. Shell Programming and Scripting

To transpose row into column

Hi All, In shell, I have below data coming from some some text file as below: . 351706 5861.8 0.026 0.012 12.584 0.026 0.012 12.582 0.000 0.000 0.000 Now i need the above data to be transposed as below 351706... (16 Replies)
Discussion started by: Anamica
16 Replies

8. Shell Programming and Scripting

Transpose row to column

I'm using the testawk.awk from the following thread https://www.unix.com/shell-programming-and-scripting/18897-row-column-transpose.htmlI'm getting the following output fieldname1 data1 fieldname2 data2 fieldname3 data3 How can I get like this instead 1 fieldname1 data1 2 fieldname2 data2... (1 Reply)
Discussion started by: makkan
1 Replies

9. Shell Programming and Scripting

How transpose column in a row?

Hello guys, First of all happy holidays and happy new year. I'm new in bioinformatic and also it is my first time that I write in this forum. Therefore, sorry if I make some mistakes. I'm writing to ask your help to fix a problem: I have a file like this: gene1 GO:0016491|GO:0055114... (8 Replies)
Discussion started by: Salvatore_espos
8 Replies

10. UNIX for Beginners Questions & Answers

Transpose the Row and column

Hi, I have data in form of A ram B shyam C seeta D geeta A bob B methew C Richad D Mike and i want it in this form. A B C D ram shyam seeta geeta bob methew Richard Mike. please help by providing the scripting for this. (3 Replies)
Discussion started by: ricbha
3 Replies
fmt(1)							      General Commands Manual							    fmt(1)

NAME
fmt - format text SYNOPSIS
width] [file...] DESCRIPTION
The command is a simple text formatter that fills and joins lines to produce output lines of (up to) the number of characters specified in the width option. The default width is 72. concatenates the arguments. If none are given, formats text from the standard input. Blank lines are preserved in the output, as is the spacing between words. does not fill lines beginning with a period for compatibility with Nor does it fill lines starting with Indentation is preserved in the output and input lines with differing indentation are not joined (unless is used). can also be used as an in-line text filter for the command: reformats the text between the cursor location and the end of the paragraph. Options recognizes the following options: Crown margin mode. Preserve the indentation of the first two lines within a paragraph and align the left margin of each subsequent line with that of the second line. This is useful for tagged paragraphs. Split lines only. Do not join short lines to form longer ones. This prevents sample lines of code, and other such "formatted" text, from being unduly combined. Fill output lines to up to width columns. WARNINGS
The width option is acceptable for BSD compatibility, but it may go away in future releases. SEE ALSO
nroff(1), vi(1). fmt(1)
All times are GMT -4. The time now is 09:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy