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 > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
rare problem -reinstalling formatting nothing is working simaich8 Linux 0 11-04-2007 02:07 AM
Formatting Substitution Command Not Working in vi ERPKEN UNIX for Advanced & Expert Users 11 05-06-2007 09:36 PM
plugging out value from a textfile snowfrost Shell Programming and Scripting 7 01-22-2007 04:30 AM
looping a array inside inside ssh is not working, pls help reldb Shell Programming and Scripting 5 07-07-2006 10:32 AM
how to find Script file location inside script asami Shell Programming and Scripting 10 03-15-2006 12:57 AM

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 07-01-2007
tekline tekline is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 15
formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command.
I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the
the awk command statement shown here. Please help.

<<<contents of msgfile.txt>>>
$ cat msgfile.txt
Firstname1,Lastname1,Initial
Firstname2,Lastname2,Initial2
Firstname3,Lastname3,Initial3
Firstname4,Lastname4,Initial4
Firstname5,Lastname5,Initial5


<<<program code - this needs to be within ksh>>>
#!usr/bin/ksh




awk -F":" '{ print $1 "\t" $2 "\t" $3 }' msgfile.txt

<<<script output>>>
$ ksh tmail2.ksh
Firstname1,Lastname1,Initial
Firstname2,Lastname2,Initial2
Firstname3,Lastname3,Initial3
Firstname4,Lastname4,Initial4
Firstname5,Lastname5,Initial5
  #2 (permalink)  
Old 07-01-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Registered User
  
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Quote:
awk -F":" '{ print $1 "\t" $2 "\t" $3 }' msgfile.txt

should be,

Code:
awk -F"," '{ print $1 "\t" $2 "\t" $3 }' msgfile.txt
because the columns are seperated by a comma.

Output:

Quote:
Firstname1 Lastname1 Initial
Firstname2 Lastname2 Initial2
Firstname3 Lastname3 Initial3
Firstname4 Lastname4 Initial4
Firstname5 Lastname5 Initial5
  #3 (permalink)  
Old 07-01-2007
kamitsin's Avatar
kamitsin kamitsin is offline
Registered User
  
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Since i like using printf for formatting in awk , you can try this also,

Code:
awk -F"," '{printf"%-20s %-20s %-20s\n",$1,$2,$3}' msgfile.txt
Output:

Quote:
Firstname1 Lastname1 Initial
Firstname2 Lastname2 Initial2
Firstname3 Lastname3 Initial3
Firstname4 Lastname4 Initial4
Firstname5 Lastname5 Initial5
  #4 (permalink)  
Old 07-01-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Or:

Code:
{ IFS=',';printf "%s\t" $(<infile);printf "\n";}
  #5 (permalink)  
Old 07-01-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Code:
# awk 'BEGIN{FS=",";OFS="\t"}{print $1,$2,$3}' file
Firstname1      Lastname1       Initial
Firstname2      Lastname2       Initial2
Firstname3      Lastname3       Initial3
Firstname4      Lastname4       Initial4
Firstname5      Lastname5       Initial5
  #6 (permalink)  
Old 07-03-2007
tekline tekline is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 15
Thanks for all the help! It works now.
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 06:36 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