Report printing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Report printing
# 1  
Old 01-27-2013
Report printing

Hi. i am trying to print the contents of my text file with delimiter : separating them.

Code:
6:15:ABC ABD:ABB ABE:
2:20:AEE ABH:ACC AAA:

i have completed my header for the report but i am having problem with my contents. i am trying to read in the data with the code below.

Code:
{ while read 'num1:num2:alpha1:alpha2:'; do
print "%-12s%12d%12d%12d\n" "$num1" "$num2 "$alpha1" "$alpha2"
done } < $file

it tells me my
Code:
'num1:num2:alpha1:alpha2:'

not a valid identifier

Last edited by Scrutinizer; 01-27-2013 at 10:49 AM.. Reason: quote tags -> code tags for data sample
# 2  
Old 01-27-2013
Perhaps you need something more like:
Code:
while IFS=: read num1 num2 alpha1 alpha2 junk; do
  printf "%-12s%12d%12d%12d\n" "$num1" "$num2" "$alpha1" "$alpha2"
done < $file

Notes:
  • I missed where "$file" was set, but I presume it is
  • Changed "print" to "printf"
  • Added " after $num2
  • It's also useful to add "junk" after the last "while read" field, in case there are additional fields you don't care about, otherwise they become part of the last field read.
# 3  
Old 01-27-2013
Thanks for your reply. Sorry for the mistake as i typed it out instead of copying. $file was set already in my program. i get an error syntax error for my while line when i tried your code. it says read: 6:15:ABC ABD:ABB ABE: syntax error in expression ( error token is "6")
# 4  
Old 01-27-2013
Please tell me which shell you are using (please don't tell me it's C-Shell), and paste your exact script and input file (if possible!)

edit: seems to be Bash:
Code:
$ strings $(which bash) | grep -i token
%s%s%s: %s (error token is "%s")

edit 2: You need to change the formatting from "%d" to "%s" - these are strings, not numbers.
# 5  
Old 01-27-2013
Slight change to Scott's solution:
Code:
printf "%-12d%12d%12s%12s\n" "$num1" "$num2" "$alpha1" "$alpha2"

This is assuming that your actual data is as per the sample shown.
It's always better to use %s instead of %d when you are unsure about the data.
# 6  
Old 01-27-2013
Hi. its bash that im using. the error is still the same after changing my code. the error seems to happen when i start reading the 1st line.

edit: Hi scott. May i know what do i do with the code that u have provided?
Code:
$ strings $(which bash) | grep -i token
%s%s%s: %s (error token is "%s")


Last edited by One_2_three; 01-27-2013 at 11:21 AM..
# 7  
Old 01-27-2013
We're not going to second guess what you've done. Please post the code.

edit: You need do nothing with that code. It was only to find in which shell the string "error token" could be found.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printing, SYSPRINTER, IP printing

Dear readers, We have a printer problem with a UNIX system. The OS is Unix IRIX 6.5 We have connected a printerto the system. If we then make a test print everything goes well . (IP printing) But if we make a print from the "orrga,i"program. Then we see all the printouts stuck within the... (3 Replies)
Discussion started by: SergevdH
3 Replies

2. Shell Programming and Scripting

Why its printing like this?

Hi, when i use the following awk i will get the output like double time printed values and the 2nd time only its giving data, please help me to find this for ex: awk code: file_name=$1 file_name1=$2 ctn=$(awk 'FNR==NR{a=$4;}$2 in a{t=a-$4;print $2,(FNR==1)?"":t"@"}' ${file_name}... (3 Replies)
Discussion started by: Shenbaga.d
3 Replies

3. UNIX for Dummies Questions & Answers

Sco Unix printing : jobs hangs in queue - printing via lp versus hpnpf

Hi, We have a Unix 3.2v5.0.5. I installed a printer via scoadmin, HP network printer manager with network peripheral name (hostname and ipadres are in /etc/hosts). This is the configuration file : Code: root@sco1 # cat configurationBanner: on:AlwaysContent types: simpleDevice:... (0 Replies)
Discussion started by: haezeban
0 Replies

4. Windows & DOS: Issues & Discussions

Linux to Windows Printing: PDF starts printing from middle of page.

We are using Red Hat. We have a issue like this: We want to print from Linux, to a printer attached to a Windows machine. What we want to print is a PDF. It prints, but the printing starts from the middle of the page. In the report, there is no space at the top but still printing starts from the... (5 Replies)
Discussion started by: rohan69
5 Replies

5. Shell Programming and Scripting

Generating a report -Formatted printing -Urgent

Hi, My aim is to generate a report using shell script. There are various formats fields coloumns etc. I want to print in a single line (row) but in different coloumn as given below: field1 field2 field3 field4 ....... ....... ...... ....... The spacing... (1 Reply)
Discussion started by: jisha
1 Replies

6. UNIX for Advanced & Expert Users

printing \n

Hi all, In a script I need to print a string: print "\n"; but i am not able to print the above mentioned string... Please help. Regards Rochit (5 Replies)
Discussion started by: rochitsharma
5 Replies

7. Shell Programming and Scripting

Printing

Hey, I'm trying to print in HP laserjet 2420 by using the command: lp -olandscape (file) For some reason it does not come out as landscape but as portrait. Help please. 10x. P.S. I'm using csh (0 Replies)
Discussion started by: Kofiko
0 Replies

8. UNIX for Dummies Questions & Answers

Printing

How do I configure a UNIX printer to print to a Windows PC with vt320 emulation (0 Replies)
Discussion started by: sowlix
0 Replies

9. UNIX for Advanced & Expert Users

Printing Problems in unix ... ( Bar-cdoe - Ip Printing)

Hi guys ... i need ur help with some printing problem in unix ... first prob. : i wanna print from my NCR unix to an Win NT , Ip based printing server ( HP JetDirect ) . My issue , is it possible to print directly to an Ip address from unix ? How do i make it work to get any results ?... (3 Replies)
Discussion started by: QuickSilver
3 Replies

10. UNIX for Dummies Questions & Answers

Printing

Do all UNIX systems have the ability to print to an ASCII file? If so, is this a common thing to do, for reports or other output? Thank you for your response. (3 Replies)
Discussion started by: SYMTRAX
3 Replies
Login or Register to Ask a Question