The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove duplicate rows of a file based on a value of a column risk_sly UNIX for Dummies Questions & Answers 7 09-26-2008 07:26 AM
convert rows into column cdfd123 Shell Programming and Scripting 3 01-11-2008 12:54 PM
Look up column in a flat file jambesh Shell Programming and Scripting 5 09-18-2006 06:44 AM
Factorize some rows in a column frebo UNIX for Dummies Questions & Answers 5 03-21-2006 06:41 AM
Converting Pivot file to flat file vskr72 Shell Programming and Scripting 2 10-18-2005 05:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-10-2008
srinikal srinikal is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
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:
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:
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 srinikal; 10-10-2008 at 05:20 AM.. Reason: e-mail address removed
  #2 (permalink)  
Old 10-10-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
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?! Sorry staff, but that sounds rude to me.
  #3 (permalink)  
Old 10-10-2008
srinikal srinikal is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
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 (permalink)  
Old 10-10-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
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 (permalink)  
Old 10-10-2008
srinikal srinikal is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
I actually didn't mean it ...
  #6 (permalink)  
Old 10-10-2008
casman46 casman46 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
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;
Closed Thread

Bookmarks

Tags
perl, perl shift, shift, shift perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0