Sponsored Content
Full Discussion: Pad Zeros at the end
Top Forums Shell Programming and Scripting Pad Zeros at the end Post 302581408 by ahamed101 on Tuesday 13th of December 2011 06:15:31 AM
Old 12-13-2011
Traditional way!
Code:
echo 12121 | awk '{printf $0;while(len-->0){printf char}}' len=5 char=9

HTH
--ahamed
This User Gave Thanks to ahamed101 For This Post:
 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

pad Zeros

Hi can I know command to pad Zeros to a value I get 16 and I need to send 0000000016 (5 Replies)
Discussion started by: mgirinath
5 Replies

2. Shell Programming and Scripting

Pad zeros to a number

Pad zeros to a number and assign it to a variable like i get 1 in $i ,i want it to be $i as 01 (6 Replies)
Discussion started by: anumkoshy
6 Replies

3. Programming

How to right pad with zeros using sprintf?

I need to right-pad with zeros a string by using (s)printf. I looked up the manual and tried with printf("%-19s", buffer); which right-pad the string with spaces. So I tried printf("%019s", buffer); which left-pad the string with zeros. So I tried both printf("%-019s", buffer);... (9 Replies)
Discussion started by: emitrax
9 Replies

4. Shell Programming and Scripting

Reformat a string and pad space at the end

I need to read in the string from input file and reform it by cut each segment and check the last segement lenght. If the last segment length is not as expected (see below segment file or table. It is predefined), then pad enough space. Old string FU22222222CA6666666666AKxvbFMddreeadBP999... (1 Reply)
Discussion started by: menglm
1 Replies

5. Shell Programming and Scripting

Pad space at the end of string and reformat

I need to read in the string from input file and reform it by cut each segment and check the last segement lenght. If the last segment length is not as expected (see below segment file or table. It is predefined), then pad enough space. Old string FU22222222CA6666666666AKxvbFMddreeadBP999... (11 Replies)
Discussion started by: menglm
11 Replies

6. Shell Programming and Scripting

How to pad with leading zeros for current time?

I'm using cygwin bash to submit scheduled tasks (kinda like cron jobs) in windows and the following script is giving me grief. I need to format the current time with leading zeros before 10AM for the hour field. In this example, I manually typed in "09:50" instead of using the `printf...`... (2 Replies)
Discussion started by: siegfried
2 Replies

7. UNIX for Beginners Questions & Answers

Pad 0 to the right

I need to pad 0 to a number on the right. to make it 9 digit in total. My number is 2457 output should be 245700000 Please do wrap your samples/codes into CODE TAGS as per forum rules. (3 Replies)
Discussion started by: varun22486
3 Replies
DEVNAME(3)						   BSD Library Functions Manual 						DEVNAME(3)

NAME
devname -- get device name LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/stat.h> #include <stdlib.h> char * devname(dev_t dev, mode_t type); char * devname_r(dev_t dev, mode_t type, char *buf, int len); char * fdevname(int fd); char * fdevname_r(int fd, char *buf, int len); DESCRIPTION
The devname() function returns a pointer to the name of the block or character device in /dev with a device number of dev, and a file type matching the one encoded in type which must be one of S_IFBLK or S_IFCHR. To find the right name, devname() asks the kernel via the kern.devname sysctl. If it is unable to come up with a suitable name, it will format the information encapsulated in dev and type in a human-readable format. The fdevname() and fdevname_r() function obtains the device name directly from a file descriptor pointing to a character device. If it is unable to come up with a suitable name, these functions will return a NULL pointer. devname() and fdevname() return the name stored in a static buffer which will be overwritten on subsequent calls. devname_r() and fdevname_r() take a buffer and length as argument to avoid this problem. EXAMPLES
int fd; struct stat buf; char *name; fd = open("/dev/tun"); fstat(fd, &buf); printf("devname is /dev/%s ", devname(buf.st_rdev, S_IFCHR)); printf("fdevname is /dev/%s ", fdevname(fd)); SEE ALSO
stat(2) HISTORY
The devname() function appeared in 4.4BSD. The fdevname() function appeared in FreeBSD 8.0. BSD
February 22, 2005 BSD
All times are GMT -4. The time now is 12:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy