Sponsored Content
Full Discussion: Printf problem
Top Forums Shell Programming and Scripting Printf problem Post 302422587 by L0ckz0r on Wednesday 19th of May 2010 12:21:26 AM
Old 05-19-2010
Printf problem

I am having a major problem with printf, The more I pad it, the less I see Smilie

The problem is in the first function, report
Am I ruining output somewhere? I wont print out the names propely, it cuts them off or deletes them completely Smilie

Code:
#!/bin/bash

report()
{
    printf "%-10s" STUD# 
    printf "%-20s" Name 
    printf "%-10s" A1  A2  A3  A4  A5  EXE  TUT  EXAM  TOTAL
    echo
    echo "----------------------------------------------------------------------------------------------------------"

    IFS2=$IFS
    exec 0<"$FILE"

    IFS=":"

    while read STUDNO USRNM A1 A2 A3 A4 A5 e1 e2 e3 e4 e5 e6 e7 e8 e9 e10 TUT EXAM
    do
        IFS=$IFS2
        NAME=`searchPasswd "$USRNM"`
        IFS=":"

        printf "%-10s" $STUDNO 
        printf "%-20s" $NAME
        #printf "%-10s" $A1 $A2 $A3 $A4 $A5 $e1 $TUT $EXAM
        echo
        
    done
    IFS=$IFS2

    
}

searchPasswd()
{    
    A=`sed -n "/$1/p" /etc/passwd` 
        newName=`echo "$A" | cut -f 5 -d ":"` 
        newName=`echo "$newName" | cut -f 1 -d ","` 
        echo $newName
}

#Set arguments
if [ ! -z "$1" ] && [ ! -z "$2" ]
then
    report=$1
    FILE=$2
    
    #Check file is good
    if [ ! -f $FILE ]; then
          echo "$FILE : does not exists"
          exit 1
       elif [ ! -r $FILE ]; then
          echo "$FILE: can not read"
          exit 2    
       fi

    echo "Report type is ------->" $report 
    echo "Filename is ---------->" $FILE

    report $FILE
else
    echo "fail"
fi

 

10 More Discussions You Might Find Interesting

1. Programming

disturbing problem with PRINTF() !!

hello everybody, here is my problem: ________________________________________ #include <stdio.h> int main() { int i=10; printf("value is %i",i); return 0; } _________________________________________ when i compile and execute, nothing appears on screen!! but if i replace the printf... (2 Replies)
Discussion started by: brain_processin
2 Replies

2. UNIX for Advanced & Expert Users

awk printf problem

Hi Friends, Can anyone guide me how to compute sum of column4 from the below file x using awk command? when i do using awk I'm getting sum 7482350198352648.000000 which is not accurate. $ cat x 56,232,dfgjkhdfj,,56,anand 56,22,dfgjkhdfj,7482347823453123.97834 ,56,Khan 56,23,dfgjkhdfj, ... (6 Replies)
Discussion started by: krishna
6 Replies

3. UNIX for Dummies Questions & Answers

Problem with "printf"

Hi All, I've one problem with printf. Iam printing some field values from one file "file.txt" using printf, which is resulting anonymously. awk '{ printf (" %-6s\n", substr($0,18,23)) }' file.txt But the same printf is workin fine as per my expectation, if I try as below: ... (1 Reply)
Discussion started by: Lokesha
1 Replies

4. Shell Programming and Scripting

perl: printf indentation problem

hi all, im having a problem with using perl printf. my requirement is to print a string (like ) at the right most end of the screen. i tried this perl script, but it fails with an error; #!/usr/bin/perl use strict; use warnings; my $scrW = 0; my $str = `stty size`; # get the... (5 Replies)
Discussion started by: wolwy_pete
5 Replies

5. Shell Programming and Scripting

printf problem

I have the following code: $ awk '{ printf "%-10s %s\n", $1, $2, $3, $4, $5, $5, $6 }' file i can only print the first 2 elements ($1,$2). How can i print all the elements to appear like this: aardvark 5555553 jhfjhfjkg efiigig ejkfjkej wjkdjk alpo-net 5553412 ... (2 Replies)
Discussion started by: DDoS
2 Replies

6. Shell Programming and Scripting

Awk printf problem

Hi, I've got a basic problem using printf statement in awk. I want to write float values with always 8 characters width. Examples : 1.345678 12.45678 123.4567 1234.678 -23.5678 -2.45678 -23456.8 ..... I cannot find the right printf format %8.1f, %7.5f.... Can anyone help ?... (4 Replies)
Discussion started by: cazhot
4 Replies

7. Shell Programming and Scripting

printf problem

In one of the scripts I am using pintf function as following printf "%s%s%s\n" "$f1" "$f2" "$f3" f3 variable contains a string of 10 characters. However it has value first 7 character and last 3 characters are empty. Example Aaaaaaa<3 spaces> bbbbbbb<3 spaces> ccccccc<3 spaces>... (4 Replies)
Discussion started by: varunrbs
4 Replies

8. Shell Programming and Scripting

problem with printf in shell script

i have written small script as follows: name="hi hello" printf "%-20s" $name This gives me strange output. -20s format is applied on both word of string. i.e it displays both word hi and hello in space of 20 length. I want to display entire string "hi hello" in length of 20 space. plz... (2 Replies)
Discussion started by: admc123
2 Replies

9. Shell Programming and Scripting

Problem with printf in UNIX KSH shell

Hi ALL, I am using SunOS 5.9 and KSH(bin/ksh) The problem am facing is error message diaplyed on screen printf: 12099415.79 not completely converted printf: + expected numeric value printf: 11898578.29 not completely converted When i try printing with The output is... (6 Replies)
Discussion started by: selvankj
6 Replies

10. Shell Programming and Scripting

Problem running plsql using printf command on bash shell

I am running plsql using printf on a shell, but i am getting some strange error, can someone point what exactly am i missing, $ echo $SHELL /bin/bash $ printf " > SET serveroutput ON trimspool on feed off echo off > declare > p_val number; > d_val varchar2(10); > begin > SELECT... (1 Reply)
Discussion started by: kamauv234
1 Replies
REPORT-CLI(1)							 LIBREPORT MANUAL						     REPORT-CLI(1)

NAME
report-cli - Work with ABRT problem directories from command line. SYNOPSIS
report-cli [-vsp] -L[PREFIX] [PROBLEM_DIR] report-cli [-vsp] -e EVENT PROBLEM_DIR report-cli [-vsp] -a[y] PROBLEM_DIR report-cli [-vsp] -c[y] PROBLEM_DIR report-cli [-vsp] -r[y|o|d] PROBLEM_DIR DESCRIPTION
report-cli is a command line tool that manages application crashes and other problems caught by abrtd daemon, or created by other programs using libreport. It enables access to, manipulation of problem data, and reporting. OPTIONS
-L[PREFIX] List possible events [which start with PREFIX] -e EVENT Run EVENT on PROBLEM_DIR -a, --analyze Run analyze event(s) on PROBLEM_DIR -c, --collect Run collect event(s) on PROBLEM_DIR -r, --report Analyze, collect and report problem data in PROBLEM_DIR -d, --delete Remove PROBLEM_DIR after reporting -y, --always Noninteractive: don't ask questions, assume positive answer to all of them -o, --report-only With -r: do not run analyzers, run only reporters -v, --verbose Be verbose -s Log to syslog -p Add program names to log -V, --version Display version and exit AUTHORS
o ABRT team LIBREPORT 2.1.11 06/18/2014 REPORT-CLI(1)
All times are GMT -4. The time now is 11:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy