Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Pivoting data based on a header field Post 303032445 by Scrutinizer on Monday 18th of March 2019 12:17:42 PM
Old 03-18-2019
Hi you can try adapting the following approach to your needs:


Code:
$ awk 'NR==1{n=split($0,H); next} {for(i=2;i<=NF;i++) print $1,H[i],$i}' FS=, OFS=, file
0050,001, 
0050,001f,0
0050,002, 
0050,002f,0
0050,003, 
0050,003f,0
0050,004, 
0050,004f,1
0050,005,*
0050,005f,7
0050,006, 
0050,006f,7
0050,007, 
0050,007f,7
0060,001, 
0060,001f,0
0060,002, 
0060,002f,0
0060,003, 
0060,003f,7
0060,004, 
0060,004f,0
0060,005,*
0060,005f,7
0060,006, 
0060,006f,0
0060,007, 
0060,007f,0


Last edited by Scrutinizer; 03-18-2019 at 03:27 PM..
This User Gave Thanks to Scrutinizer For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

generating reports based on time field of network data

hi i have data extracted in the following format ranging around 300000 to 800000 records in a text file , the format is of network data . No. Time Source Destination Protocol 1 1998-06-05 17:20:23.569905 HP_61:aa:c9 HP_61:aa:c9 ... (1 Reply)
Discussion started by: renukaprasadb
1 Replies

2. Shell Programming and Scripting

extract data in a csv file based on a certain field.

I have a csv file that I need to extract some data from depending on another field after reading info from another text file. The text file would say have 592560 in it. The csv file may have some data like so Field 1 Field2 Field3 Field4 Field5 Field6 20009756 1 ... (9 Replies)
Discussion started by: GroveTuckey
9 Replies

3. UNIX for Dummies Questions & Answers

Sorting data in file based on field in another file

Hi, I have two files, one of which I would like to sort based on the order of the data in the second. I would like to do this using a simple unix statement. My two files as follows: File 1: 12345 1 2 2 2 0 0 12349 0 0 2 2 1 2 12350 1 2 1 2 2 2 . . . File2: 12350... (3 Replies)
Discussion started by: kasan0
3 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

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

6. Shell Programming and Scripting

awk : Filter a set of data to parse header line and last field of multiple same match.

Hi Experts, I have a data with multiple entry , I want to filter PKG= & the last column "00060110" or "00088150" in the output file: ############################################################################################### PKG= P8SDB :: VGS = vgP8SOra vgP8SDB1 vgP8S001... (5 Replies)
Discussion started by: rveri
5 Replies

7. Shell Programming and Scripting

Pivoting csv field from pipe delimited file

Hello All, Thanks for taking time to read through the thread and for providing any possible solution. I am trying to pivot a comma separated field in a pipe delimited file. Data looks something like this: Field1|Field2 123|345,567,789 234|563,560 345|975,098,985,397,984 456|736 Desired... (8 Replies)
Discussion started by: svks1985
8 Replies

8. 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

9. UNIX for Beginners Questions & Answers

Problem with getting awk to multiply a field by a value set based on condition of another field

Hi, So awk is driving me crazy on this one. I have searched everywhere and read man, docs and every related post Google can find and still no luck. The actual files I need to run this on are sensitive in nature, but it is the same thing as if I needed to calculate weighted grades for multiple... (15 Replies)
Discussion started by: cotilloe
15 Replies
ISCNTRL(3)						   BSD Library Functions Manual 						ISCNTRL(3)

NAME
iscntrl -- control character test LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <ctype.h> int iscntrl(int c); DESCRIPTION
The iscntrl() function tests for any control character. The value of the argument must be representable as an unsigned char or the value of EOF. In the ASCII character set, this includes the following characters (preceded by their numeric values, in octal): 000 NUL 001 SOH 002 STX 003 ETX 004 EOT 005 ENQ 006 ACK 007 BEL 010 BS 011 HT 012 NL 013 VT 014 NP 015 CR 016 SO 017 SI 020 DLE 021 DC1 022 DC2 023 DC3 024 DC4 025 NAK 026 SYN 027 ETB 030 CAN 031 EM 032 SUB 033 ESC 034 FS 035 GS 036 RS 037 US 177 DEL RETURN VALUES
The iscntrl() function returns zero if the character tests false and returns non-zero if the character tests true. COMPATIBILITY
The 4.4BSD extension of accepting arguments outside of the range of the unsigned char type in locales with large character sets is considered obsolete and may not be supported in future releases. The iswcntrl() function should be used instead. SEE ALSO
ctype(3), isalnum_l(3), iswcntrl(3), ascii(7) STANDARDS
The iscntrl() function conforms to ISO/IEC 9899:1990 (``ISO C90''). BSD
July 17, 2005 BSD
All times are GMT -4. The time now is 10:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy