Converting Column to Rows in a Flat file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Converting Column to Rows in a Flat file
# 1  
Old 10-10-2008
Converting Column to Rows in a Flat file

Hi,
Request To guide me in writing a shell program for the following requirement:
Example:if the Input File contains the follwing data

Input File Data:
Code:
80723240029,12,323,443,88,98,7,98,67,87
80723240030,12,56,6,,,3,12,56,6,7,2,3,12,56,6,7,2,3,88,98,7,98,67,87
80723240031,56,57,d,88,98,7,98,67,87,88,98,7,98,67,87
80723250032,45,hg,3

Background:After First column every 6 columns are identified as one setand first column is the key to identify the records.

I have to convert the data as follows:
Output File Data:
Code:
80723240029,12,323,443,88,98,7
80723240029,98,67,87
80723240030,12,56,6,,,3
80723240030,12,56,6,7,2,3
80723240030,12,56,6,7,2,3
80723240030,88,98,7,98,67,87
80723240031,56,57,d,88,98,7
80723240031,98,67,87,88,98,7
80723240031,98,67,87
80723250032,45,hg,3


Thanks in Advance,
srinivas

Last edited by joeyg; 05-02-2012 at 04:08 PM.. Reason: e-mail address removed, CodeTags
# 2  
Old 10-10-2008
Anything you tried yet yourself and what about looking here again on your own instead of waiting for a mail when the "job" is finished?! Smilie Sorry staff, but that sounds rude to me.
# 3  
Old 10-10-2008
Hi Zaxxon,
The data format which i gave is the final stage wherein iam actually struck,prior to bring it to this page other things to split actual file into two file and identifying the first column.

i posted the question wherein iam unable to proceed further..

I didn't understand where it was rude pls explain..
# 4  
Old 10-10-2008
Simply posting your email address and asking to be informed when we did your work.
People here are helping out of fun/compassion/a mood/boredom, whatever. No one gets paid for it so the way you wrote was somewhat demanding an inappropriate.
# 5  
Old 10-10-2008
I actually didn't mean it ...
# 6  
Old 10-10-2008
As I understand your problem, using Perl (and your sample data) I believe this will give you what you want.

#!/usr/bin/perl
my @fields;
my @hold;
my $key1;
my $x;
my $i;
open INPUT, "<file6";
open OUTPUT, ">outfile";
while(<INPUT>)
{
chomp;
@fields = split /,/, $_;
$key1 = $fields[0];
shift @fields;
while ( defined($fields[0]) )
{
for ($i = 1; $i < 7; $i++)
{
if ( defined($fields[0]) )
{
$hold[$i] = $fields[0];
shift @fields;
}
else
{
last;
}
}
$x = join ",", @hold;
$array1{$key1} = $x;
print OUTPUT "$key1$array1{$key1}\n";
@hold = ( );
}
}
close INPUT;
close OUTPUT;
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting Single Column into Multiple rows

Hi .. anyone can you help me ? i need to convert text below into multiple columns interface; GigabitEthernet0/0/0/0 description; TRUNK_PE-D2-JT2-VPN_Gi0/0/0/0_TO_ME4-A-JKT-JT_4/1/1_1G mtu 9212 negotiation auto interface; GigabitEthernet0/0/0/0.11 description; tes encapsulation;... (1 Reply)
Discussion started by: mad3linux
1 Replies

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

3. UNIX for Dummies Questions & Answers

Converting column to rows for every 3 lines in the column

Hi gurus! Please help me with this one. I have an file with the following contents: a b c d e f g h i j I would like to make to transform it to look like this as my output file: a,b,c d,e,f (4 Replies)
Discussion started by: kokoro
4 Replies

4. Shell Programming and Scripting

Converting rows to column

i have output of script as below name,roll_no,01-05-12,02-05-12,03-05-12 sam,12,24,24,24 jon,145,24,24,22 van,29,24,22,24 i want to convert these into columns as output is not fixed please tell me how to convert 1st row in to 1st columns likewise,as many rows are there are to be converted... (4 Replies)
Discussion started by: sagar_1986
4 Replies

5. Shell Programming and Scripting

Help with converting XML to Flat file

Hi Friends, I want to convert a XML file to flat file. Sample I/p: <?xml version='1.0' encoding='UTF-8' ?> <DataFile xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' contactCount='4999' date='2012-04-14' time='22:00:14' xsi:noNamespaceSchemaLocation='gen .xsd'> <Contact... (3 Replies)
Discussion started by: karumudi7
3 Replies

6. Shell Programming and Scripting

Converting entries from rows to column

Hi all, I need your help on a multiple row entry into different columns. And do the same with all the entries in file. File example (showing 2 entries only, there are many like these): >ABC * AGA-AUUCUC-CGGUUCAAUCU ||| UCUAUAACCGCGCCGAGUUAGU >ABC * AGAUAU-GCUGCAGGCUCAAUUG ||||||... (2 Replies)
Discussion started by: atulkakrana
2 Replies

7. UNIX for Dummies Questions & Answers

Audit Flat File - # of Columns / Rows

We receive a file which usually has 40 to 50 million rows. I want to set up an audit process by which everytime we receive a file we audit it for # of rows and total number of columns. So if the # of rows is around 1 million on a particular day, I want to raise a flag or send an email....and if... (3 Replies)
Discussion started by: priya33184
3 Replies

8. UNIX for Advanced & Expert Users

Converting the date format in a flat file

Hi All, I am new to this forum, could any one help me out in resolving the below issue. Input of the flat file contains several lines of text for example find below: 5022090,2,4,7154,88,,,,,4/1/2011 0:00,Z,L,2 5022090,3,1,6648,88,,,,,4/1/2011 0:00,Z,,1... (0 Replies)
Discussion started by: av_sagar
0 Replies

9. Shell Programming and Scripting

Converting a flat file in XML

Hello Friends, I am new to UNIX shell scripting. Using bash....Could you please help me in converting a flat file into an XML style output file. Flat file: (Input File entries looks like this) John Miller: 617-569-7996:15 Bunting lane, staten Island, NY: 10/21/79: 60600 The... (4 Replies)
Discussion started by: humkhn
4 Replies

10. Shell Programming and Scripting

Converting Single Column into Multiple rows

i have single column which is starting with same string(many number of rows) i have to convert each into a single row.how can i do that? laknar std mes 23 55 laknar isd phone no address amount 99 I have to convert above like below. laknar|std|mes|23|55 laknar|isd|phone... (3 Replies)
Discussion started by: laknar
3 Replies
Login or Register to Ask a Question