Sponsored Content
Full Discussion: Split column into rows
Top Forums UNIX for Beginners Questions & Answers Split column into rows Post 302991731 by saravananravim on Wednesday 15th of February 2017 10:25:39 PM
Old 02-15-2017
Split column into rows

Hi,

I have input dataset as below:

Code:
Cl.jenn,1051,ABCD
JEN.HEA,9740|1517|8119|2145,ZZZZ,REPEAT
Rich.Sm,
Ann.Car,3972|4051|1064|4323|4122|2394|2574|4507
Sta.for,7777,ABCD,UUUU
Sm.Ric,
Ch.LRD, 
Eh.ab,
Gr.sh,

Expected output:
-------------------
Code:
Cl.jenn,1051,ABCD
JEN.HEA,9740,ZZZZ,REPEAT
JEN.HEA,1517,ZZZZ,REPEAT
JEN.HEA,8119,ZZZZ,REPEAT
JEN.HEA,2145,ZZZZ,REPEAT
Rich.Sm,
Ann.Car,3972
Ann.Car,4051
Ann.Car,1064
Ann.Car,4323
Ann.Car,4122
Ann.Car,2394
Ann.Car,2574
Ann.Car,4507
Sta.for,7777,ABCD,UUUU
Sm.Ric,
Ch.LRD,
Eh.ab,
Gr.sh,

I am using below command to achieve this:
--------------------------------------------------
Code:
awk -F',' -v OFS=',' '{n=split($2,s,"|"); for(i=1;i<=n;i++) {$2=s[i];print}}' test.txt

Actual output is :
-------------------
Code:
Cl.jenn,1051,ABCD
JEN.HEA,9740,ZZZZ,REPEAT
JEN.HEA,1517,ZZZZ,REPEAT
JEN.HEA,8119,ZZZZ,REPEAT
JEN.HEA,2145,ZZZZ,REPEAT
Ann.Car,3972
Ann.Car,4051
Ann.Car,1064
Ann.Car,4323
Ann.Car,4122
Ann.Car,2394
Ann.Car,2574
Ann.Car,4507
Sta.for,7777,ABCD,UUUU
Ch.LRD,

Some records are filtered to display. Any suggestions pls???

Last edited by Don Cragun; 02-16-2017 at 12:01 AM.. Reason: Add CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

split rows

Hi I wanted to split rows based on the number of 1's present in 21st field(21st field is 40 length field) so I wrote the below awk code. However, the tool that I am using to invoke the command is not recognising the command. So, could you please help me to translate this command to sed? awk... (5 Replies)
Discussion started by: ahmedwaseem2000
5 Replies

2. Shell Programming and Scripting

Split rows

Hi all, I need a simple bin/sh script FILE1: ab1 gegege swgdeyedg ac2 jxjjxjxjxxjxjx ad3 ae4 xjxjxj zhzhzh ahahs af5 sjsjsjs ssjsjsjsj sjsjsj ag6 shshshshs sjjssj shhshshs myScript.sh has to return: ROW ab1 ROW ac2 ROW ad3 ROW ae4 In other words: "ROW " + the first world... (3 Replies)
Discussion started by: ric79
3 Replies

3. Shell Programming and Scripting

Split single rows to multiple rows ..

Hi pls help me out to short out this problem rm PAB113_011.out rm: PAB113_011.out: override protection 644 (yes/no)? n If i give y it remove the file. But i added the rm command as a part of ksh file and i tried to remove the file. Its not removing and the the file prompting as... (7 Replies)
Discussion started by: sri_aue
7 Replies

4. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
4 Replies

5. UNIX for Dummies Questions & Answers

merging rows into new file based on rows and first column

I have 2 files, file01= 7 columns, row unknown (but few) file02= 7 columns, row unknown (but many) now I want to create an output with the first field that is shared in both of them and then subtract the results from the rest of the fields and print there e.g. file 01 James|0|50|25|10|50|30... (1 Reply)
Discussion started by: A-V
1 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. Shell Programming and Scripting

awk to sum a column based on duplicate strings in another column and show split totals

Hi, I have a similar input format- A_1 2 B_0 4 A_1 1 B_2 5 A_4 1 and looking to print in this output format with headers. can you suggest in awk?awk because i am doing some pattern matching from parent file to print column 1 of my input using awk already.Thanks! letter number_of_letters... (5 Replies)
Discussion started by: prashob123
5 Replies

8. Shell Programming and Scripting

awk split columns after matching on rows and summing the last column

input: chr1 1 2 3 chr1 1 2 4 chr1 2 4 5 chr2 3 6 9 chr2 3 6 10 Code: awk '{a+=$4}END{for (i in a) print i,a}' input Output: chr112 7 chr236 19 chr124 5 Desired output: chr1 1 2 7 chr2 3 6 19 chr1 2 4 5 (1 Reply)
Discussion started by: jacobs.smith
1 Replies

9. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

10. UNIX for Beginners Questions & Answers

How to split one long column into multiple rows with 3 each ?

I have a large csv dataset like this : A value1 A value2 A value3 B value1 B value2 B value3 C value1 C value2 C value3 what I expected output is :A value1 value2 value3 B value1 value2 value3 C value1 value2 value3 I'm thinking of use like awk, columns , but haven't find a proper... (4 Replies)
Discussion started by: nengcheng
4 Replies
DateTime::Locale::tr(3) 				User Contributed Perl Documentation				   DateTime::Locale::tr(3)

NAME
DateTime::Locale::tr SYNOPSIS
use DateTime; my $dt = DateTime->now( locale => 'tr' ); print $dt->month_name(); DESCRIPTION
This is the DateTime locale package for Turkish. DATA
This locale inherits from the DateTime::Locale::root locale. It contains the following data. Days Wide (format) Pazartesi SalX CarXamba PerXembe Cuma Cumartesi Pazar Abbreviated (format) Pzt Sal Car Per Cum Cmt Paz Narrow (format) P S C P C C P Wide (stand-alone) Pazartesi SalX CarXamba PerXembe Cuma Cumartesi Pazar Abbreviated (stand-alone) Pzt Sal Car Per Cum Cmt Paz Narrow (stand-alone) P S C P C C P Months Wide (format) Ocak Xubat Mart Nisan MayXs Haziran Temmuz AXustos Eyluel Ekim KasXm AralXk Abbreviated (format) Oca Xub Mar Nis May Haz Tem AXu Eyl Eki Kas Ara Narrow (format) O X M N M H T A E E K A Wide (stand-alone) Ocak Xubat Mart Nisan MayXs Haziran Temmuz AXustos Eyluel Ekim KasXm AralXk Abbreviated (stand-alone) Oca Xub Mar Nis May Haz Tem AXu Eyl Eki Kas Ara Narrow (stand-alone) O X M N M H T A E E K A Quarters Wide (format) 1. ceyrek 2. ceyrek 3. ceyrek 4. ceyrek Abbreviated (format) C1 C2 C3 C4 Narrow (format) 1 2 3 4 Wide (stand-alone) 1. ceyrek 2. ceyrek 3. ceyrek 4. ceyrek Abbreviated (stand-alone) C1 C2 C3 C4 Narrow (stand-alone) 1 2 3 4 Eras Wide Milattan Oence Milattan Sonra Abbreviated MOe MS Narrow MOe MS Date Formats Full 2008-02-05T18:30:30 = 05 Xubat 2008 SalX 1995-12-22T09:05:02 = 22 AralXk 1995 Cuma -0010-09-15T04:44:23 = 15 Eyluel -10 Cumartesi Long 2008-02-05T18:30:30 = 05 Xubat 2008 1995-12-22T09:05:02 = 22 AralXk 1995 -0010-09-15T04:44:23 = 15 Eyluel -10 Medium 2008-02-05T18:30:30 = 05 Xub 2008 1995-12-22T09:05:02 = 22 Ara 1995 -0010-09-15T04:44:23 = 15 Eyl -10 Short 2008-02-05T18:30:30 = 05.02.2008 1995-12-22T09:05:02 = 22.12.1995 -0010-09-15T04:44:23 = 15.09.-010 Default 2008-02-05T18:30:30 = 05 Xub 2008 1995-12-22T09:05:02 = 22 Ara 1995 -0010-09-15T04:44:23 = 15 Eyl -10 Time Formats Full 2008-02-05T18:30:30 = 18:30:30 UTC 1995-12-22T09:05:02 = 09:05:02 UTC -0010-09-15T04:44:23 = 04:44:23 UTC Long 2008-02-05T18:30:30 = 18:30:30 UTC 1995-12-22T09:05:02 = 09:05:02 UTC -0010-09-15T04:44:23 = 04:44:23 UTC Medium 2008-02-05T18:30:30 = 18:30:30 1995-12-22T09:05:02 = 09:05:02 -0010-09-15T04:44:23 = 04:44:23 Short 2008-02-05T18:30:30 = 18:30 1995-12-22T09:05:02 = 09:05 -0010-09-15T04:44:23 = 04:44 Default 2008-02-05T18:30:30 = 18:30:30 1995-12-22T09:05:02 = 09:05:02 -0010-09-15T04:44:23 = 04:44:23 Datetime Formats Full 2008-02-05T18:30:30 = 05 Xubat 2008 SalX 18:30:30 UTC 1995-12-22T09:05:02 = 22 AralXk 1995 Cuma 09:05:02 UTC -0010-09-15T04:44:23 = 15 Eyluel -10 Cumartesi 04:44:23 UTC Long 2008-02-05T18:30:30 = 05 Xubat 2008 18:30:30 UTC 1995-12-22T09:05:02 = 22 AralXk 1995 09:05:02 UTC -0010-09-15T04:44:23 = 15 Eyluel -10 04:44:23 UTC Medium 2008-02-05T18:30:30 = 05 Xub 2008 18:30:30 1995-12-22T09:05:02 = 22 Ara 1995 09:05:02 -0010-09-15T04:44:23 = 15 Eyl -10 04:44:23 Short 2008-02-05T18:30:30 = 05.02.2008 18:30 1995-12-22T09:05:02 = 22.12.1995 09:05 -0010-09-15T04:44:23 = 15.09.-010 04:44 Default 2008-02-05T18:30:30 = 05 Xub 2008 18:30:30 1995-12-22T09:05:02 = 22 Ara 1995 09:05:02 -0010-09-15T04:44:23 = 15 Eyl -10 04:44:23 Available Formats d (d) 2008-02-05T18:30:30 = 5 1995-12-22T09:05:02 = 22 -0010-09-15T04:44:23 = 15 Ed (d E) 2008-02-05T18:30:30 = 5 Sal 1995-12-22T09:05:02 = 22 Cum -0010-09-15T04:44:23 = 15 Cmt EEEd (d EEE) 2008-02-05T18:30:30 = 5 Sal 1995-12-22T09:05:02 = 22 Cum -0010-09-15T04:44:23 = 15 Cmt H (H) 2008-02-05T18:30:30 = 18 1995-12-22T09:05:02 = 9 -0010-09-15T04:44:23 = 4 HHmm (HH:mm) 2008-02-05T18:30:30 = 18:30 1995-12-22T09:05:02 = 09:05 -0010-09-15T04:44:23 = 04:44 hhmm (hh:mm a) 2008-02-05T18:30:30 = 06:30 PM 1995-12-22T09:05:02 = 09:05 AM -0010-09-15T04:44:23 = 04:44 AM HHmmss (HH:mm:ss) 2008-02-05T18:30:30 = 18:30:30 1995-12-22T09:05:02 = 09:05:02 -0010-09-15T04:44:23 = 04:44:23 hhmmss (hh:mm:ss a) 2008-02-05T18:30:30 = 06:30:30 PM 1995-12-22T09:05:02 = 09:05:02 AM -0010-09-15T04:44:23 = 04:44:23 AM Hm (HH:mm) 2008-02-05T18:30:30 = 18:30 1995-12-22T09:05:02 = 09:05 -0010-09-15T04:44:23 = 04:44 hm (h:mm a) 2008-02-05T18:30:30 = 6:30 PM 1995-12-22T09:05:02 = 9:05 AM -0010-09-15T04:44:23 = 4:44 AM Hms (H:mm:ss) 2008-02-05T18:30:30 = 18:30:30 1995-12-22T09:05:02 = 9:05:02 -0010-09-15T04:44:23 = 4:44:23 hms (h:mm:ss a) 2008-02-05T18:30:30 = 6:30:30 PM 1995-12-22T09:05:02 = 9:05:02 AM -0010-09-15T04:44:23 = 4:44:23 AM M (L) 2008-02-05T18:30:30 = 2 1995-12-22T09:05:02 = 12 -0010-09-15T04:44:23 = 9 Md (dd/MM) 2008-02-05T18:30:30 = 05/02 1995-12-22T09:05:02 = 22/12 -0010-09-15T04:44:23 = 15/09 MEd (dd/MM E) 2008-02-05T18:30:30 = 05/02 Sal 1995-12-22T09:05:02 = 22/12 Cum -0010-09-15T04:44:23 = 15/09 Cmt MMM (LLL) 2008-02-05T18:30:30 = Xub 1995-12-22T09:05:02 = Ara -0010-09-15T04:44:23 = Eyl MMMd (dd MMM) 2008-02-05T18:30:30 = 05 Xub 1995-12-22T09:05:02 = 22 Ara -0010-09-15T04:44:23 = 15 Eyl MMMEd (dd MMM E) 2008-02-05T18:30:30 = 05 Xub Sal 1995-12-22T09:05:02 = 22 Ara Cum -0010-09-15T04:44:23 = 15 Eyl Cmt MMMMd (dd MMMM) 2008-02-05T18:30:30 = 05 Xubat 1995-12-22T09:05:02 = 22 AralXk -0010-09-15T04:44:23 = 15 Eyluel MMMMEd (dd MMMM E) 2008-02-05T18:30:30 = 05 Xubat Sal 1995-12-22T09:05:02 = 22 AralXk Cum -0010-09-15T04:44:23 = 15 Eyluel Cmt mmss (mm:ss) 2008-02-05T18:30:30 = 30:30 1995-12-22T09:05:02 = 05:02 -0010-09-15T04:44:23 = 44:23 ms (mm:ss) 2008-02-05T18:30:30 = 30:30 1995-12-22T09:05:02 = 05:02 -0010-09-15T04:44:23 = 44:23 y (y) 2008-02-05T18:30:30 = 2008 1995-12-22T09:05:02 = 1995 -0010-09-15T04:44:23 = -10 yM (M/yyyy) 2008-02-05T18:30:30 = 2/2008 1995-12-22T09:05:02 = 12/1995 -0010-09-15T04:44:23 = 9/-010 yMEd (dd.MM.yyyy EEE) 2008-02-05T18:30:30 = 05.02.2008 Sal 1995-12-22T09:05:02 = 22.12.1995 Cum -0010-09-15T04:44:23 = 15.09.-010 Cmt yMMM (MMM y) 2008-02-05T18:30:30 = Xub 2008 1995-12-22T09:05:02 = Ara 1995 -0010-09-15T04:44:23 = Eyl -10 yMMMEd (dd MMM y EEE) 2008-02-05T18:30:30 = 05 Xub 2008 Sal 1995-12-22T09:05:02 = 22 Ara 1995 Cum -0010-09-15T04:44:23 = 15 Eyl -10 Cmt yMMMM (MMMM y) 2008-02-05T18:30:30 = Xubat 2008 1995-12-22T09:05:02 = AralXk 1995 -0010-09-15T04:44:23 = Eyluel -10 yQ (Q yyyy) 2008-02-05T18:30:30 = 1 2008 1995-12-22T09:05:02 = 4 1995 -0010-09-15T04:44:23 = 3 -010 yQQQ (QQQ y) 2008-02-05T18:30:30 = C1 2008 1995-12-22T09:05:02 = C4 1995 -0010-09-15T04:44:23 = C3 -10 yyMM (MM/yy) 2008-02-05T18:30:30 = 02/08 1995-12-22T09:05:02 = 12/95 -0010-09-15T04:44:23 = 09/-10 yyMMM (MMM yy) 2008-02-05T18:30:30 = Xub 08 1995-12-22T09:05:02 = Ara 95 -0010-09-15T04:44:23 = Eyl -10 yyQ (Q yy) 2008-02-05T18:30:30 = 1 08 1995-12-22T09:05:02 = 4 95 -0010-09-15T04:44:23 = 3 -10 yyQQQQ (QQQQ yy) 2008-02-05T18:30:30 = 1. ceyrek 08 1995-12-22T09:05:02 = 4. ceyrek 95 -0010-09-15T04:44:23 = 3. ceyrek -10 yyyy (y) 2008-02-05T18:30:30 = 2008 1995-12-22T09:05:02 = 1995 -0010-09-15T04:44:23 = -10 Miscellaneous Prefers 24 hour time? Yes Local first day of the week Pazartesi SUPPORT
See DateTime::Locale. AUTHOR
Dave Rolsky <autarch@urth.org> COPYRIGHT
Copyright (c) 2008 David Rolsky. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. This module was generated from data provided by the CLDR project, see the LICENSE.cldr in this distribution for details on the CLDR data's license. perl v5.16.2 2013-08-25 DateTime::Locale::tr(3)
All times are GMT -4. The time now is 07:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy