%.*s function in shells

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting %.*s function in shells
# 1  
Old 08-20-2002
%.*s function in shells

Can anyone tell me now to achieve the printf %.*s functionality in shell script, (sh/ksh). I want to append x number of (same)characters at the end of a file without using normal looping.


# 2  
Old 08-20-2002
Tools just try the printf command

Hereby the man page(sunos) for the printf command, i hope this help

# 3  
Old 08-20-2002
thanks for the reply, but you will see from the Usage section: -

Field widths and precisions cannot be specified as *.

Even using the %.*s functionality is not ideal, I would need to create a very long string, hope the required length would never exceed this and then use the .* width specifier. The ideal solution would be to specify a character and a repitition count to an existing tool, sed/awk etc?

# 4  
Old 08-20-2002
Take a look at the awk command:

man awk
# 5  
Old 08-20-2002
Interesting problem. I have tested the script below and it seems to work.
#! /usr/bin/ksh

ostring=$1   # original string
char=$2      # character to append
nchar=$3     # how many chars are needed

typeset -Z${nchar} suffix=0
suffix=$(echo $suffix | sed s/0/${char}/g)
echo ${ostring}${suffix}

exit 0

# 6  
Old 08-20-2002
thanks, but again I don't think awk supports the width specifier for strings, it does for numbers though.

# 7  
Old 08-20-2002
Thanks Perderabo

I like your style of thinking

I actually mistyped my original post, I need to append x characters to EACH LINE in a file, but the script you gave works great and I can modify it.

Thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Please what are shells?

I mean like this: http://shells.red-pill.eu/ Can anyone explain how this works? I hope my post is not spam. I think its related to linux. Thank you (1 Reply)
Discussion started by: postcd
1 Replies

2. UNIX for Dummies Questions & Answers


Lets say my default shell is bash and then i load up csh and then ksh. How would i exit csh without exiting ksh? so basically i gone from bash > csh > ksh and i wish to close csh (2 Replies)
Discussion started by: Bill Thompson
2 Replies

3. UNIX for Dummies Questions & Answers

shells and scripts

So in UNIX, I understand that there are several different shells you can be in: C, Bourne, Bourne Again, Korn, etc. I also know that you can write scripts for the shells, by assigning it by #!/bin/csh, or sh, etc. If I am working in the csh, do I have to write the script for the csh? Or can it... (1 Reply)
Discussion started by: bjstaff
1 Replies

4. Shell Programming and Scripting

Calling a function which uses expect from a shells script

Hi all, This is the first time i am using expect. I am trying to call a function with in the shell script. The function will shh to a new server and will pass the password using expect and send. I need help in calling the fuction i am getting follaowing errors... here the script ... (8 Replies)
Discussion started by: firestar
8 Replies

5. Shell Programming and Scripting

Switching between shells

I don't know why, but it just isn't working how I want it to work. You might want to run it to see what I mean. Or you might be a genius (or just really good at unix) and know just by looking at it what the problem is. Have fun trying to figure this one out.:wall: (11 Replies)
Discussion started by: nowruzr
11 Replies

6. UNIX for Advanced & Expert Users

why we have different shells?

Can you pls. tell me, why we have different shells in UNIX OS ( Eg. SunOs) and also I would like to know what is the specific difference b/w SVR and BSD ? Thanks. (2 Replies)
Discussion started by: shahnazurs
2 Replies

7. UNIX for Advanced & Expert Users

How to set a label/number for a function in a shells script

Can any one let me know like how cn i set an label or number for each function whihc are there in an shells script: for example cd /opt/qcom/test/ function1() function2() function3() ------- i ahe a script like this .now i want to count each of this function like 1, 2, 3,............... (3 Replies)
Discussion started by: lalitka
3 Replies

8. Shell Programming and Scripting

control sub-shells

Hi all, New to shell scripting, I would like to know if it is possible to pass commands to a shell, which has been launched by a parent shell. Example: #!/bin/ksh # # Launch and command shells # . mySecondShell.ksh #this launches a sub-shell #now is something like this possible?... (7 Replies)
Discussion started by: MarkZWEERS
7 Replies

9. Linux

Version of Shells?

Can anyone tell me the version of shells for bash mc pdksh tcsh zsh For Red Hat Enterprise 4? Thank you very much! (2 Replies)
Discussion started by: Xplore
2 Replies

10. UNIX for Advanced & Expert Users


I have came across the definitions of these shells korn bourne c etc .. but honestly till now i din't get the exact difference between these threes , the advantages ..... can anyone pinpoint me where it actually lies ..... don;t include me answers like aliasing in c is posible and not in bourne ..... (3 Replies)
Discussion started by: dino_leix
3 Replies
Login or Register to Ask a Question