Sponsored Content
Top Forums Shell Programming and Scripting Converting Column to Rows in a Flat file Post 302245636 by casman46 on Friday 10th of October 2008 03:32:39 PM
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;
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
DBIPROF(1p)						User Contributed Perl Documentation					       DBIPROF(1p)

NAME
dbiprof - command-line client for DBI::ProfileData SYNOPSIS
See a report of the ten queries with the longest total runtime in the profile dump file prof1.out: dbiprof prof1.out See the top 10 most frequently run queries in the profile file dbi.prof (the default): dbiprof --sort count See the same report with 15 entries: dbiprof --sort count --number 15 DESCRIPTION
This tool is a command-line client for the DBI::ProfileData. It allows you to analyze the profile data file produced by DBI::ProfileDumper and produce various useful reports. OPTIONS
This program accepts the following options: --number N Produce this many items in the report. Defaults to 10. If set to "all" then all results are shown. --sort field Sort results by the given field. Sorting by multiple fields isn't currently supported (patches welcome). The available sort fields are: total Sorts by total time run time across all runs. This is the default sort. longest Sorts by the longest single run. count Sorts by total number of runs. first Sorts by the time taken in the first run. shortest Sorts by the shortest single run. key1 Sorts by the value of the first element in the Path, which should be numeric. You can also sort by "key2" and "key3". --reverse Reverses the selected sort. For example, to see a report of the shortest overall time: dbiprof --sort total --reverse --match keyN=value Consider only items where the specified key matches the given value. Keys are numbered from 1. For example, let's say you used a DBI::Profile Path of: [ DBIprofile_Statement, DBIprofile_Methodname ] And called dbiprof as in: dbiprof --match key2=execute Your report would only show execute queries, leaving out prepares, fetches, etc. If the value given starts and ends with slashes ("/") then it will be treated as a regular expression. For example, to only include SELECT queries where key1 is the statement: dbiprof --match key1=/^SELECT/ By default the match expression is matched case-insensitively, but this can be changed with the --case-sensitive option. --exclude keyN=value Remove items for where the specified key matches the given value. For example, to exclude all prepare entries where key2 is the method name: dbiprof --exclude key2=prepare Like "--match", If the value given starts and ends with slashes ("/") then it will be treated as a regular expression. For example, to exclude UPDATE queries where key1 is the statement: dbiprof --match key1=/^UPDATE/ By default the exclude expression is matched case-insensitively, but this can be changed with the --case-sensitive option. --case-sensitive Using this option causes --match and --exclude to work case-sensitively. Defaults to off. --delete Sets the "DeleteFiles" option to DBI::ProfileData which causes the files to be deleted after reading. See DBI::ProfileData for more details. --dumpnodes Print the list of nodes in the form of a perl data structure. Use the "-sort" option if you want the list sorted. --version Print the dbiprof version number and exit. AUTHOR
Sam Tregar <sam@tregar.com> COPYRIGHT AND LICENSE
Copyright (C) 2002 Sam Tregar This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself. SEE ALSO
DBI::ProfileDumper, DBI::Profile, DBI. perl v5.12.3 2011-05-06 DBIPROF(1p)
All times are GMT -4. The time now is 06:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy