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
Flat file Krishnaramjis Shell Programming and Scripting 9 05-08-2008 10:28 PM
Converting .ps file to .pdf file from where it is broken sunitachoudhury UNIX for Advanced & Expert Users 5 04-07-2008 11:13 AM
Pivot variable record length file and change delimiter thomasr Shell Programming and Scripting 3 10-08-2007 08:40 PM
Converting a Delimited File to Fixed width file raghavan.aero Shell Programming and Scripting 2 06-06-2007 02:44 PM
Converting a text file to a csv file primowalker Shell Programming and Scripting 4 12-06-2005 05:02 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-18-2005
vskr72 vskr72 is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 11
Converting Pivot file to flat file

I have a file in this format.
P1 P2 P3.........................
A001 v11 v21 v31......................
A002 v12 v22 v32............................
A003 v13 v23 v33..........................
A004 v14 v24 v34..............................
.
.
.
A00n

This has to be flattened in this format

A001 P1 v11
A001 P2 v21
A001 P3 v31
A001 P4 v41
...
...
...

Please let me know if ther is a easy way in awk to do it?

Kumar
  #2 (permalink)  
Old 10-18-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,100
Maybe...
Code:
#! /usr/bin/ksh

read one
while read field line ; do
        echo "$field ${one%% *} $line"
        one=${one#* }
done
exit 0
  #3 (permalink)  
Old 10-18-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
or with awk:

nawk -f vs.awk myFile.txt

vs.awk:
Code:
FNR == 1 { n=split("1 " $0, arr, FS); next }
{
  for(i=2; i <= n; i++)
    print $1, arr[i], $i
}
Sponsored Links
Closed Thread

Bookmarks

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 09:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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