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
GLPSOL(1)							   User Commands							 GLPSOL(1)

NAME
GLPSOL: - manual page for GLPSOL: GLPK LP/MIP Solver, v4.43 SYNOPSIS
glpsol [options...] filename DESCRIPTION
General options: --mps read LP/MIP problem in fixed MPS format --freemps read LP/MIP problem in free MPS format (default) --lp read LP/MIP problem in CPLEX LP format --glp read LP/MIP problem in GLPK format --math read LP/MIP model written in GNU MathProg modeling language -m filename, --model filename read model section and optional data section from filename (same as --math) -d filename, --data filename read data section from filename (for --math only); if model file also has data section, it is ignored -y filename, --display filename send display output to filename (for --math only); by default the output is sent to terminal --seed value initialize pseudo-random number generator used in MathProg model with specified seed (any integer); if seed value is ?, some random seed will be used --mincost read min-cost flow problem in DIMACS format --maxflow read maximum flow problem in DIMACS format --simplex use simplex method (default) --interior use interior point method (LP only) -r filename, --read filename read solution from filename rather to find it with the solver --min minimization --max maximization --scale scale problem (default) --noscale do not scale problem -o filename, --output filename write solution to filename in printable format -w filename, --write filename write solution to filename in plain text format --ranges filename write sensitivity analysis report to filename in printable format (simplex only) --tmlim nnn limit solution time to nnn seconds --memlim nnn limit available memory to nnn megabytes --check do not solve problem, check input data only --name probname change problem name to probname --wmps filename write problem to filename in fixed MPS format --wfreemps filename write problem to filename in free MPS format --wlp filename write problem to filename in CPLEX LP format --wglp filename write problem to filename in GLPK format --log filename write copy of terminal output to filename -h, --help display this help information and exit -v, --version display program version and exit LP basis factorization options: --luf LU + Forrest-Tomlin update (faster, less stable; default) --cbg LU + Schur complement + Bartels-Golub update (slower, more stable) --cgr LU + Schur complement + Givens rotation update (slower, more stable) Options specific to simplex solver: --primal use primal simplex (default) --dual use dual simplex --std use standard initial basis of all slacks --adv use advanced initial basis (default) --bib use Bixby's initial basis --ini filename use as initial basis previously saved with -w (disables LP presolver) --steep use steepest edge technique (default) --nosteep use standard "textbook" pricing --relax use Harris' two-pass ratio test (default) --norelax use standard "textbook" ratio test --presol use presolver (default; assumes --scale and --adv) --nopresol do not use presolver --exact use simplex method based on exact arithmetic --xcheck check final basis using exact arithmetic Options specific to interior-point solver: --nord use natural (original) ordering --qmd use quotient minimum degree ordering --amd use approximate minimum degree ordering (default) --symamd use approximate minimum degree ordering Options specific to MIP solver: --nomip consider all integer variables as continuous (allows solving MIP as pure LP) --first branch on first integer variable --last branch on last integer variable --mostf branch on most fractional variable --drtom branch using heuristic by Driebeck and Tomlin (default) --pcost branch using hybrid pseudocost heuristic (may be useful for hard instances) --dfs backtrack using depth first search --bfs backtrack using breadth first search --bestp backtrack using the best projection heuristic --bestb backtrack using node with best local bound (default) --intopt use MIP presolver (default) --nointopt do not use MIP presolver --binarize replace general integer variables by binary ones (assumes --intopt) --fpump apply feasibility pump heuristic --gomory generate Gomory's mixed integer cuts --mir generate MIR (mixed integer rounding) cuts --cover generate mixed cover cuts --clique generate clique cuts --cuts generate all cuts above --mipgap tol set relative mip gap tolerance to tol SEE ALSO
For description of the MPS and CPLEX LP formats see the Reference Manual at /usr/share/doc/glpk-doc/glpk.pdf For description of the modeling language see "GLPK: Modeling Language GNU MathProg" at /usr/share/doc/glpk-doc/gmpl.pdf COPYRIGHT
Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Andrew Makhorin, Department for Applied Informatics, Moscow Aviation Institute, Moscow, Russia. All rights reserved. This program has ABSOLUTELY NO WARRANTY. This program is free software; you may re-distribute it under the terms of the GNU General Public License version 3 or later. GLPSOL
: GLPK LP/MIP Solver, v4.43 March 2010 GLPSOL(1)
All times are GMT -4. The time now is 08:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy