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
How to changes rows to columns in a file oracle123 Shell Programming and Scripting 4 07-31-2008 04:38 AM
How to convert a single column into several rows and columns? ashton_smith UNIX for Dummies Questions & Answers 5 05-24-2008 04:44 PM
shell script required to convert rows to columns suresh3566 Shell Programming and Scripting 2 05-07-2008 05:25 AM
deleting rows & columns form a csv file code19 Shell Programming and Scripting 2 03-13-2008 10:06 AM
Columns to rows mgirinath Shell Programming and Scripting 16 11-29-2007 07:03 PM

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

Join Date: Aug 2008
Posts: 7
Question awk - reformating rows into columns

looking to do the following...

What the data looks like

Code:
server1 02/01/2008 groups 10
server1 03/01/2008 groups 15
server1 04/01/2008 groups 20
server2 02/01/2008 users 50
server2 03/01/2008 users 75
server2 04/01/2008 users 100
server2 04/01/2008 users 125

What I would like the data to look like
Code:
server1  groups 15 20
seerver2 users  100 125
Thanks,
JD
  #2 (permalink)  
Old 08-13-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
perl:

Code:
open(FH,"<filename");
while(<FH>){
	@arr=split(" ",$_);
	$t=sprintf("%s %s",$arr[0],$arr[2]);
	$hash{$t}=sprintf("%s %s",$hash{$t},$arr[3]);
}
close(FH);
for $key (keys %hash){
	@temp=split(" ",$hash{$key});
	print $key," ",$temp[$#temp-1]," ",$temp[$#temp],"\n";
}
Closed Thread

Bookmarks

Tags
awk reformat parse

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 06:53 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