Trying to space columns in a report


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to space columns in a report
# 1  
Old 11-10-2004
Trying to space columns in a report

I have a program that calculates shipping cost for an item and prints the information to a file. I cannot seem to get the lines to print with equal spacing in columns.

I need data like this to be aligned into columns:

Optical Mouse 5 A $25
Compaq Presario 3 C $100
PS2 2 D $18

I am trying to use awk to do it but having no luck.

Code:
echo "$Name;$Quantity;$Class;$Total" | awk -F";" '{printf "%s %10s %10s %10s\n", $1, $2, $3, $4}' >> ShipInfo

# 2  
Old 11-10-2004
Try:
Code:
echo "$Name;$Quantity;$Class;$Total" | awk -F";" '{printf "%-10s %-10s %-10s $%5.4f\n", $1, $2, $3, substr($4,2)}' >> ShipInfo

# 3  
Old 11-10-2004
Thanks a lot, that is working.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to print columns with space

Hello I am trying to pull specific columns from an output file that contains spaces and make it a variable.. Here is a piece of the output file and my command: Host1 UNIX /vol/volume/my stuff When I pull in the data into my variable the word stuff is left off - I need this as part of my... (10 Replies)
Discussion started by: fmalvest
10 Replies

2. Shell Programming and Scripting

Insert space in specific column among many columns

Hello, I have some problem in inserting the space for the pairs of columns. I have the input file : I used this code below in replacing it using space in specific column (replace space in each two columns) sed -e "s/,/ /2" -e "s/,/ /3" inputfile Output showed : However, I have many... (3 Replies)
Discussion started by: awil
3 Replies

3. UNIX for Dummies Questions & Answers

How convert space separated list to matched columns?

Hi I have been racking my (limited) brains to get this to work without success I have a file output which is a list of lists - ie a single column of data that is separated by space into sub lists below - I need to both split this so that each list is in a separate column (eg tab or semicolon... (8 Replies)
Discussion started by: Manchesterpaul
8 Replies

4. Shell Programming and Scripting

Insert space or pattern between columns in a data file

I have a data file where three data sets are written in three columns. Can I increase the space between the columns without reading them? Also can I insert particular patterns, say comma between 1st and 2nd column and colon between 2nd and 3rd column? (13 Replies)
Discussion started by: hbar
13 Replies

5. Shell Programming and Scripting

Romove columns and replace a space with a character

Hi, I have a file containing this: testvol1 unix enabled testvol2 unix enabled testvol3 unix enabled testvol3 qtree1 unix enabled testvol3 qtree2 unix enabled testvol4 unix enabled testvol4 qtree1 unix enabled And I want an output of this: testvol1... (4 Replies)
Discussion started by: niap21
4 Replies

6. Shell Programming and Scripting

Columns to rows with space

Hi, My input is in the following way a b c d e f I would like to have it printed as a b c d e f Any awk scripts are appreciated. (1 Reply)
Discussion started by: jacobs.smith
1 Replies

7. UNIX for Dummies Questions & Answers

help needed: remove space between certain columns

dear all, i have a data looks like this (i have 3000 columns): rs123 A T T G C C C C C C A A A A A A A A A A A ... rs154 T T G C C C C C A A A A A A A A A A T T G ... rs126 A C C C C C A A A A A A A A A A A A T T G ... I want to remove all the space after the 2nd column and make the... (2 Replies)
Discussion started by: forevertl
2 Replies

8. UNIX for Dummies Questions & Answers

Deleting columns from a space delimited text file

I have a space delimited text file with 1,000,000+ columns and 100 rows. I want to delete columns 2 through 5 (2 and 5) included from the text file. How do I do that? Thanks. (3 Replies)
Discussion started by: evelibertine
3 Replies

9. Shell Programming and Scripting

help with delimiting columns with a space

Hi all, i am writting a script to fix some problems we have with data that we need that contains 1000s of records. I have a text file with 3 columns of data. The problem is there should be a space between the end of the first column and the start of the second column. The majority of the data is... (7 Replies)
Discussion started by: borderblaster
7 Replies

10. HP-UX

How to add space in between columns in VI editor

Hi, I am trying to add space after 3rd and 6th column for editing a file in special format. How should I achieve in VI?. So, is it possible to do in it in sed ? thanks vipa (1 Reply)
Discussion started by: vipas
1 Replies
Login or Register to Ask a Question