Some Help to print out information


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Some Help to print out information
# 1  
Old 07-24-2011
Some Help to print out information

Need abit of help to print out information.

I have something like this

Code:
Logitech:My store:34.3:23
Altec Lansing:Partner:45.9:20

with : as delimiter

and i need an output arranged like this

Code:
Logitech             My Store   34.3   23 
Altec Lansing        Partner    45.9   20

tried few methods with awk but no luck yet Smilie

Last edited by radoulov; 07-24-2011 at 05:18 PM.. Reason: Code tags.
# 2  
Old 07-24-2011
Code:
awk -F: '{ 
  printf "%-15s %-10s %6.1f %d\n", $1, $2, $3, $4 
  }' infile

This User Gave Thanks to radoulov For This Post:
# 3  
Old 07-25-2011
Sorry mind I asked another question here?
So lets say if I want to multiply 34.3 with 23, is it possible to print on the 5th column? Where the 5th column is the total of the first row.

Code:
Logitech             My Store   34.3   23  788.9 
Altec Lansing        Partner    45.9   20  918

How do ya put it inside here?

Code:
awk -F: '{    printf "%-15s %-10s %6.1f %d\n", $1, $2, $3, $4    }' infile


Last edited by aLHaNz; 07-25-2011 at 11:05 AM.. Reason: Code tags.
# 4  
Old 07-25-2011
Yes:

Code:
awk -F: '{ 
  printf "%-15s %-10s %6.1f %d %.1f\n", $1, $2, $3, $4, $3 * $4 
  }' infile

# 5  
Old 07-25-2011
haha nice!! so i assume the "1f" is use to calculate the amount of f3 and f4?
# 6  
Old 07-25-2011
No,

.width - specify maximum string width or digits to right of decimal point.
f - is a format control letter, it tells the printf statement to print a number in floating-point notation.

Check the GUN awk manual for more details, 5.5 Using printf Statements for Fancier Printing.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Setting up Solaris 10 to print to a windows print server

Guys, I have a issue that I am trying to rectify please advise. lpstat -t shows scheduler is running printer lext644 disabled since Mon Dec 02 19:48:18 2013. available.I have restarted the printer service and it shows online but the above says disabled. I have a lot of jobs in the print... (1 Reply)
Discussion started by: terrywhitejr
1 Replies

2. UNIX for Dummies Questions & Answers

How to create a print filter that print text & image?

Currently, I have a print filter that takes a text file, that convert it into PCL which then gets to a HP printer. This works. Now I need to embedded a image file within the text file. I'm able to convert the image file into PCL and I can cat both files together to into a single document... (1 Reply)
Discussion started by: chedlee88-1
1 Replies

3. UNIX for Advanced & Expert Users

[Solved] remove all print jobs from a print queue

Hello, Sometimes i need to clear all the jobs of a print queue and it is really annoying to cancel one by one. Is there a way to cancel all print jobs for a specific print queue with a single command instead of cancelling them one by one? My AIX system is 5.3 Thank you for your attention (2 Replies)
Discussion started by: omonoiatis9
2 Replies

4. Shell Programming and Scripting

perl script to print file information - newbie

Hi I have a perl script that prints all the video and audio file information(playing duration). It works fine in one of my friends linux laptop. But it doesn't work in my both windows and linux. My friend told me I have to do install some module ( ppm instal ...... ) but I have no... (1 Reply)
Discussion started by: srijith
1 Replies

5. Shell Programming and Scripting

Print file information using ffmpeg in perl

I am trying to print file information using ffmpeg tool in perl Here is my code use strict; use warnings; use IPC::Open3; # example my $filename = $ARGV; my %videoInfo = videoInfo($filename); print "duration: " . $videoInfo{'duration'} . "\n"; print "durationsecs: " .... (0 Replies)
Discussion started by: srijith
0 Replies

6. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

7. Shell Programming and Scripting

Howto Print File Path or Print the Filename

I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction? for FILE in `cat list`; do if ; then ... (1 Reply)
Discussion started by: overkill
1 Replies

8. HP-UX

Print Problem in UNIX. Need to know the option to specify the print paper size

Hi, Could any one please let me know what is the option available in UNIX to print by specifying the paper size? We are using Unix11i. I could n't see any option specified in the 'lp' command to print the report by specifying the size of the paper. It would be of great help to me, if... (1 Reply)
Discussion started by: ukarthik
1 Replies

9. OS X (Apple)

Get print job information

Hi all, I am on a mac and I am trying to get more information about print jobs i have. "lpq" only displays the document printing, size, and job ID. I need the status (if its on hold or not). Anyway to do that in unix/cups? (5 Replies)
Discussion started by: CBarraford
5 Replies
Login or Register to Ask a Question