Pivoting a Single column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Pivoting a Single column
# 1  
Old 11-10-2008
Pivoting a Single column

Hi,

Input

Code:
ID|Name
1|a,b,c
2|d,e,f,g

I would like to get output in the following format.

Output

Code:
ID|NAME
1|a
1|b
1|c
2|d
2|e
2|f
2|g

Thanks.
# 2  
Old 11-10-2008
Hammer & Screwdriver Perhaps this works for you

Code:
> cat file60
ID|Name
1|a,b,c
2|d,e,f,g

> cat fix60.sh
#! /usr/bin/bash

IFS="|"
while read l_id l_nm
  do
  echo $l_nm | tr "," "\n" | sed "s/^/$l_id|&/"
done <file60

> fix60.sh
ID|Name
1|a
1|b
1|c
2|d
2|e
2|f
2|g

# 3  
Old 11-10-2008
With awk:
Code:
awk$ -F ",|\|" 'NR==1{print;next}
{for(i=2;i<=NF;i++){print $1"|"$i}}' file

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

2. Shell Programming and Scripting

Bring values in the second column into single line (comma sep) for uniq value in the first column

I want to bring values in the second column into single line for uniq value in the first column. My input jvm01, Web 2.0 Feature Pack Library jvm01, IBM WebSphere JAX-RS jvm01, Custom01 Shared Library jvm02, Web 2.0 Feature Pack Library jvm02, IBM WebSphere JAX-RS jvm03, Web 2.0 Feature... (10 Replies)
Discussion started by: kchinnam
10 Replies

3. Shell Programming and Scripting

Copying a single value to the entire column

Hello everone, I have a text file as input, which lokks like for exemple: # # # 12 2 3 12 12 12 12 12 12 12 It has three column. My question is, i want to copy the value of 2nd column, 1st row to the entire 2nd column. similarly for the third column also. My result... (7 Replies)
Discussion started by: dinesh.n
7 Replies

4. Shell Programming and Scripting

Paste 2 single column files to a single file

Hi, I have 2 csv/txt files with single columns. I am trying to merge them using paste, but its not working.. output3.csv: flowerbomb everlon-jewelry sofft steve-madden dolce-gabbana-watchoutput2.csv: http://www1.abc.com/cms/slp/2/Flowerbomb http://www1.abc.com/cms/slp/2/Everlon-Jewelry... (5 Replies)
Discussion started by: ajayakunuri
5 Replies

5. UNIX for Dummies Questions & Answers

Creating a two column list of date pairs form a single column list

Hi all, looking for some help here. I'm what you'd call a dirty programmer. my shell scripts might be ugly, but they (usually) function... Say I have a single column text file with a list of dates (yyyymmdd) that represent the elevation of a point on that date (I work with land subsidence, so... (2 Replies)
Discussion started by: jbrandt1979
2 Replies

6. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

7. UNIX for Dummies Questions & Answers

List several files into one single column

frtgyh (2 Replies)
Discussion started by: lucasvs
2 Replies

8. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

9. UNIX for Dummies Questions & Answers

Multiple column into single column

Hi , i have an output as follows... xxx yyyy aaaa bbb and i want it to be printed as xxx yyyy aaaa bbb Any help please... (3 Replies)
Discussion started by: appu2176
3 Replies

10. Shell Programming and Scripting

paste each 10 lines of single column to several column

Hi, I need to paste each 10 lines of single column to several columns. Please, can anyone tell me how to write in awk? Input File: 22 34 36 12 17 19 15 11 89 99 56 38 29 (4 Replies)
Discussion started by: nica
4 Replies
Login or Register to Ask a Question