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
Formatting mirusnet Shell Programming and Scripting 3 01-06-2008 11:38 PM
Formatting using awk cdunavent Shell Programming and Scripting 2 03-18-2003 02:09 PM
Text formatting to 132 columns jmossman UNIX for Dummies Questions & Answers 16 05-06-2002 08:34 PM
formatting xeron UNIX for Dummies Questions & Answers 5 03-20-2002 11:33 AM
formatting darryll777 UNIX for Dummies Questions & Answers 1 03-04-2002 01:15 PM

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

Join Date: Jan 2007
Posts: 6
Formatting info into columns

Hi

This question has kind of been asked before but I couldn't get any of the solutions to work.

I need to format fields being cut from a file into columns so it looks like a table.
e.g

Full name Address Hiredate
Joe Smith London 11.01.01
Bill King Liverpool 15.05.99
Harry Bloggs Leeds 12.11.04

I belive awk is used but I'm not sure how, if anyone could help that would be great

Thank you
  #2 (permalink)  
Old 02-01-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
awk ' { printf("%-20s%-15s%10s\n",$1" "$2,$3,$4) } ' file
  #3 (permalink)  
Old 02-01-2007
Crazy_murli Crazy_murli is offline
Registered User
  
 

Join Date: Jun 2006
Location: UK
Posts: 26
One other possible ways may be ::

cat <filename> | column -t

However, the awk one mentioned above by anbu provides more formatted output.

Cheers, Murli.
  #4 (permalink)  
Old 02-02-2007
straight_edge straight_edge is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 6
Thanks for the replies
  #5 (permalink)  
Old 02-04-2007
milo milo is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 32
Quote:
Originally Posted by Crazy_murli
One other possible ways may be ::

cat <filename> | column -t

However, the awk one mentioned above by anbu provides more formatted output.

Cheers, Murli.
Hi Cray_murli, it seems that column command doesn't exist.

I have table, would like to output fisrt column each line. Used awk as anbu's but output just in one line.

Hope your helps. Thanks.
  #6 (permalink)  
Old 02-05-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by milo
Hi Cray_murli, it seems that column command doesn't exist.

I have table, would like to output fisrt column each line. Used awk as anbu's but output just in one line.

Hope your helps. Thanks.
You might forgot to add newline character
Code:
awk ' { printf("%-20s%-15s%10s\n",$1" "$2,$3,$4) } ' file
  #7 (permalink)  
Old 02-05-2007
c2b2 c2b2 is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 29
Hi Every1,

Is there othr way to do the same, because awk will traverse each line and might become slow in case of very huge input file.

Correct me if I am wrong!
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 02:58 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