Sponsored Content
Top Forums Shell Programming and Scripting perl: printf indentation problem Post 302179151 by wolwy_pete on Thursday 27th of March 2008 05:26:02 AM
Old 03-27-2008
Data perl: printf indentation problem

hi all,
im having a problem with using perl printf. my requirement is to print a string (like [OK]) at the right most end of the screen.
i tried this perl script, but it fails with an error;
Code:
#!/usr/bin/perl 

use strict;
use warnings;

my $scrW = 0;

my $str = `stty size`;   # get the screen character width 
$str =~ m/(\d+)\s*$/;    # extract the char width
$scrW = eval($1);           # put the char width in a varable $scrW

$scrW -=10;                     # reduce the char width by 10
printf "%($scrW)s\n", "abcde";

tried to use printf with a variable as indentation length, but fails.
this type of method works in bash.
does anyone have an idea ?

thankx.
 

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. 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

4. 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

5. Shell Programming and Scripting

printf vs sprintf - perl

I would like to assign the output of printf to a variable in perl , it give me back a "1" instead of the time. How can I stuff the variable with what printf returns? Here is my code: #!/usr/bin/perl $time = localtime(time);... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

6. Shell Programming and Scripting

Printf problem

I am having a major problem with printf, The more I pad it, the less I see :( 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 :( #!/bin/bash report() { printf "%-10s" STUD# ... (2 Replies)
Discussion started by: L0ckz0r
2 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

printf (awk,perl,shell) float rounding issue

Hi guys, could someone throw some light on the following behaviour of printf (I'll start with info about the system and the tool/shell/interpreter versions)?: $ uname -a Linux linux-86if.site 3.1.0-1.2-desktop #1 SMP PREEMPT Thu Nov 3 14:45:45 UTC 2011 (187dde0) x86_64 x86_64 x86_64... (9 Replies)
Discussion started by: elixir_sinari
9 Replies

10. Programming

[Perl] Different printf formating for different print options

Hi, Struggling with single quotes, double quotes, etc. I want to print a header line, followed by lines with actual values, based on a print option. In real life it is going to be something like 15 print options and 50 values. Output will be 1 header and several value lines. In this example... (5 Replies)
Discussion started by: ejdv
5 Replies
euclen(3C)						   Standard C Library Functions 						euclen(3C)

NAME
euclen, euccol, eucscol - get byte length and display width of EUC characters SYNOPSIS
#include <euc.h> int euclen(const unsigned char *s); int euccol(const unsigned char *s); int eucscol(const unsigned char *str); DESCRIPTION
The euclen() function returns the length in bytes of the Extended Unix Code (EUC) character pointed to by s, including single-shift charac- ters, if present. The euccol() function returns the screen column width of the EUC character pointed to by s. The eucscol() function returns the screen column width of the EUC string pointed to by str. For the euclen() and euccol(), functions, s points to the first byte of the character. This byte is examined to determine its codeset. The character type table for the current locale is used for codeset byte length and display width information. USAGE
These functions will work only with EUC locales. These functions can be used safely in multithreaded applications, as long as setlocale(3C) is not called to change the locale. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |MT-Level |MT-Safe with exceptions | +-----------------------------+-----------------------------+ SEE ALSO
getwidth(3C), setlocale(3C), attributes(5) SunOS 5.10 20 Dec 1996 euclen(3C)
All times are GMT -4. The time now is 04:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy