Pivoting with awk


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Pivoting with awk
# 1  
Old 12-05-2018
Pivoting with awk

My input file(inputfile.txt):
Code:
Job name.... EXTDPL_1
Created on.. 2018-11-19 14:00:00
Modified on. 2018-11-22 11:54:46

Job name.... EXTDPL_2
Created on.. 2018-11-21 12:31:27


Modified on. 2018-11-21 12:35:28


2 records listed.
>Q

expected output:
Code:
Job name	Created on				Modified on
EXTDPL_1	2018-11-19 14:00:00		2018-11-22 11:54:46
EXTDPL_2	2018-11-21 12:31:27		2018-11-21 12:35:28

my script:
Code:
awk '/^Job name|^Created on|^Modified on/ {print $3,$4}' inputfile.txt | awk 'ORS=NR%3?FS:RS' | awk '{printf "%-40s%-11s%-12s%-11s%-12s\n",$1,$2,$3,$4,$5}'

would like to know above three awks can be clubbed into one ?
# 2  
Old 12-05-2018
How aboutawk '
Code:
awk '
NR == 1         {printf "%-40s%-23s%-23s\n", "Job name", "Created on", "Modified on"
                }
/^Job name/     {printf "%-40s", $3
                }
/^Created on/   {printf "%-11s%-12s", $3,$4
                } 
/^Modified on/  {printf "%-11s%-12s\n", $3,$4
                }
' file
Job name                                Created on             Modified on            
EXTDPL_1                                2018-11-19 14:00:00    2018-11-22 11:54:46    
EXTDPL_2                                2018-11-21 12:31:27    2018-11-21 12:35:28

This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-06-2018
Hi Rudic, thanks for reply. one question.
how to stop printing header if there are no 'Job name/Created on/Modified on' match..
# 4  
Old 12-06-2018
Move that line to the first real printout, adding a condition.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Pivoting data based on a header field

Hi Team, Could you please help me with the below scenario. I have a file which is in the below format. Zipcode,001,001f,002,002f,003,003f,004,004f,005,005f,006,006f,007,007f 0050, ,0, ,0, ,0, ,1,*,7, ,7, ,7 0060, ,0, ,0, ,7, ,0,*,7, ,0, ,0 Would need the output as below. First field... (1 Reply)
Discussion started by: saj
1 Replies

2. UNIX for Beginners Questions & Answers

Pivoting values from column to rows

I/P: I/P: 2017/01/01 a 10 2017/01/01 b 20 2017/01/01 c 40 2017/02/01 a 10 2017/02/01 b 20 2017/02/01 c 30 O/P: a b c 2017/01/01 10 20 40 2017/02/01 10 20 30 (18 Replies)
Discussion started by: Booo
18 Replies

3. Homework & Coursework Questions

Help with pivoting table shell script

input file txt file 2000 1 name 2000 2 addr 2000 3 phone 2000 4 email 1000 1 name 1000 2 addr 1000 3 phone 1000 4 email 3000 1 name 3000 2 addr 3000 ... (4 Replies)
Discussion started by: senmatrix
4 Replies

4. Shell Programming and Scripting

Pivoting using shell scripts

Hi , Please any one help using shell scripts achieve the below output(pivoting on top_cd i mean type code values will come as individual columns and fixed amount is value for that .Any help would be greate tx_id tx_amt typ_cd fixed_dis_amt 100 200 mc ... (3 Replies)
Discussion started by: mohan705
3 Replies

5. Linux

Pivoting data with awk

Hi Friends, I need to pivot data . Below is my source data Source Data PK PRTY_KEY_ID PRTY_SUB_KEY_ID KEY_COL_VAL_TX MTCH_CNFDNCE_RATE 007824822 428844791 1 #Jemmy#Pom#600 Kearsarge Way 100 007824822 429283974 1 #Jemmy#Pom#120 Broadway 100 007824822 429739103 1 #Jemmy#Pom#600 Keae Way#757... (0 Replies)
Discussion started by: patiljeevan3
0 Replies

6. Shell Programming and Scripting

Pivoting the data

Hello Unix guys, I have the following 4 column data, which is a output of db2 select query: Need to pivot the data. sample Input: Year Month Country Counts 2012 Aug Canada 114 2012 Aug USA 92 2012 Aug Mexico 3 2012 Aug ... (3 Replies)
Discussion started by: karumudi7
3 Replies

7. Shell Programming and Scripting

Vertical And Horizontal Pivoting

Hi All, My Input data is: A=1 B=2 My desired Output should be: A|B 1|2 Thanks in advance... (3 Replies)
Discussion started by: kmsekhar
3 Replies

8. Shell Programming and Scripting

Help with pivoting

Hi, I need help on how to pivot the data in UNIX. I have one input file in which The facts(FACT1,FACT2..) and PERIOD(JAN,FEB..) are columns.I need to pivot the data. For Exampe The input file and output file looks like below. Could you please help with this using awk:). INPUT: ====== ... (1 Reply)
Discussion started by: Gayathricheruku
1 Replies

9. Shell Programming and Scripting

Pivoting Dynamic rows into columns

Original file we are getting ....... Item Period Amt P1 106 1000 P1 206 1500 P1 106 2000 P2 256 5800 P2 650 7500 My output should be like this Item 106 206 256 650 ............ P1 1000 1500 0 ... (1 Reply)
Discussion started by: dprakash
1 Replies

10. UNIX for Dummies Questions & Answers

Pivoting a Single column

Hi, Input ID|Name 1|a,b,c 2|d,e,f,g I would like to get output in the following format. Output ID|NAME 1|a 1|b 1|c 2|d 2|e 2|f 2|g (2 Replies)
Discussion started by: deepakwins
2 Replies
Login or Register to Ask a Question