The UNIX and Linux Forums  

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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-18-2005
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-18-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,356
Maybe...
Code:
#! /usr/bin/ksh

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

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
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
}
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0