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
Need to get the first column of data bobk544 Shell Programming and Scripting 3 08-04-2007 05:35 PM
Column data reading FarhanNaseer Shell Programming and Scripting 1 09-19-2005 01:02 AM
File Manipulation (Move Column Position) ultimate Shell Programming and Scripting 1 03-29-2005 11:22 PM
glance RSS/VSS data column xtrix HP-UX 0 01-17-2005 10:32 AM
How can i move data files from a server to unix folder shah2 Shell Programming and Scripting 1 03-01-2004 06:38 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 05-19-2003
danhodges99
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Move data from Column to Row

Hi all,

I have a file with several columns of data, eg:

A B C D

1 2 5 1
2 2 2 2
8 4 4 4
4 2 3 4
10 9 4 4
9 7 1 2

I need to get the values from, say, column B and place them into a string separated by a semicolon, eg:

2;2;4;2;9;7

Does anyone have any ideas how to do this? Any help would be massively appreciated! Thanks.
  #2 (permalink)  
Old 05-19-2003
JoBa JoBa is offline
Registered User
  
 

Join Date: Sep 2002
Location: The Netherlands
Posts: 16
Pherhaps this script can help you:

#!/bin/ksh

for row in `tail +3 your_file | awk '{print $2}'`
do
echo "$row;\c" >your_new_file
done
  #3 (permalink)  
Old 05-19-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
That almost works, but it needs a couple corrections..

Replace > with >>, so that new information is added on to the end of your_new_file and doesn't overwrite what's already there.

Replace `tail +3 your_file | awk '{print $2}'` with `awk '{print $2}' file` so that all the numbers in the row are extracted from your_file.

-----
Oh wait, now I see why you put the tail command in.. guess it depends if A B C D is actually in the file or not..

Last edited by oombera; 05-19-2003 at 10:44 AM..
  #4 (permalink)  
Old 05-19-2003
danhodges99
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Cheers guys, works great, you've been a big help!
  #5 (permalink)  
Old 05-19-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Alternatively, you can use:

someVar=`awk '{ printf $2 ";" }' file`

if A B C D is not at the top of the file to produce output like this:

2;2;4;2;9;7;
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 03:46 PM.


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