Visit Our UNIX and Linux User Community


Print N characters in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print N characters in ksh
# 1  
Old 10-28-2010
Print N characters in ksh

Hi,

I have this header on a script:
Code:
echo "*************************************"

How can I print 1000 "*" characters without to put them on the echo command? Understand?

THIS IS AN EXAMPLE WHAT I NEED:

Code:
print "1000 *"

Or is possible to print or echo "*" characters until they fill the line page size?

Thanks

Last edited by iga3725; 10-28-2010 at 11:25 AM..
# 2  
Old 10-28-2010
many ways to skin that cat:
Code:
nawk 'BEGIN{$1000=OFS="*";print}' < /dev/null
perl -le 'print "*" x 1000'
printf "%01000d"|tr "0" "*"

# 3  
Old 10-28-2010
Hi,

Do you know if it's possible to fill the output line with "*" taking into account the size of the windows you're looking?

Thanks
# 4  
Old 10-28-2010
Quote:
Originally Posted by iga3725
Hi,

Do you know if it's possible to fill the output line with "*" taking into account the size of the windows you're looking?

Thanks
for example - the others would be similar:
Code:
nawk -v width=${COLUMNS} 'BEGIN{$width=OFS="*";print}'

# 5  
Old 10-28-2010
Umm, give me this error on ksh (AIX)

a0@server: /home/a0 # nawk -v width=${COLUMNS} 'BEGIN{$width=OFS="*";print}'
awk: 0602-562 Field $() is not correct.
The source line number is 1.

Any idea of this error?

Really appreciate your help.

Thanks again.
# 6  
Old 10-28-2010
Quote:
Originally Posted by iga3725
Umm, give me this error on ksh (AIX)

a0@server: /home/a0 # nawk -v width=${COLUMNS} 'BEGIN{$width=OFS="*";print}'
awk: 0602-562 Field $() is not correct.
The source line number is 1.

Any idea of this error?

Really appreciate your help.

Thanks again.
Hmmm... don't have AIX in front of me atm.
if you do echo $COLUMNS from shell, what do you get?
Try:
Code:
printf "%0${COLUMNS}d"|tr "0" "*"

# 7  
Old 10-28-2010
Doesn't work on AIX.. but works fine on linux... dont know what's the problem :-(

echo $COLUMNS does not retunr nothing..

thanks

Previous Thread | Next Thread
Test Your Knowledge in Computers #886
Difficulty: Medium
Phishing is the attempt to acquire sensitive information such as usernames, passwords, and credit card details directly from users by installing backdoors to operating systems.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh hidden characters in variables

Hi. I'm getting the following hidden characters \uat the start of a string after I pass in variables from the command line. I only noticed this when I set -x in my KSH script. Can anybody tell me how this happens and how to remove them? Many thanks. + STR=$'\uusername testuser1' + print... (12 Replies)
Discussion started by: user052009
12 Replies

2. Shell Programming and Scripting

ksh check for non printable characters in a string

Hi All, I am trying to find non-printable characters in a string. The sting could have alphanumeric, puntuations and characters like (*&%$#.') but not non-printable (or that is what I think they are called) which are introduced when you copy any text from DOS to unix box. Input string1:... (10 Replies)
Discussion started by: dips_ag
10 Replies

3. Shell Programming and Scripting

comparing special characters in KSH

Hi Guys, I came across a scenario where I have to check the starting character of line in a file. if it is a specile character i.e. "<" gretaer then perform action. I tried serval ways but could not get the work done. Please help me .... Thanks (6 Replies)
Discussion started by: ravi111_07
6 Replies

4. Shell Programming and Scripting

Use awk to print first 6 characters

Hi, i want to use awk to print the first 6 characters of a variable awk -F"|" '$3>0 { print $3 }' z00.unl > z001.unl but $3= 7 digits and i just want to print the first 6 digits. eg 1005779 but i want to print only 100577 (3 Replies)
Discussion started by: dealerso
3 Replies

5. Shell Programming and Scripting

Ksh: Replace backslash characters

Hi All, I have a requirement to read a line from a file with some search string, replace any backslash characters in that line and store in a variable. Shell script: replace.ksh #!/bin/bash file2=input.rtf line=`grep "Invoice Number" ${file2} | head -1 | sed 's/\\//g'` echo "start... (6 Replies)
Discussion started by: prashas_d
6 Replies

6. Shell Programming and Scripting

Print the first four characters of hostname

Hey, I'm trying to print the first four characters of the hostname of a computer. I can get it from using: hostname -s | sed 's/...........$//'" but this is when I know how many characters are in the computer name. I dont understand why some like: hostname -s | sed '/..../p' wont... (7 Replies)
Discussion started by: yxian
7 Replies

7. Shell Programming and Scripting

print 10 characters in series

suppose fileA kanika123ABC 1222222222222222 raciat5678ty 1221123333331121 jessica78ulllo 2233243223333333 so output shud be print only first 10 characters in series and rest remain same kanika123A 1222222222222222 raciat5678 1221123333331121 jessica78u ... (1 Reply)
Discussion started by: cdfd123
1 Replies

8. Shell Programming and Scripting

get last characters in ksh

Hi, Here the way the txt file looks like.. 100|abcd|6899|xyz 112|dlkja|79311| 432|adjkl|1348|iaw I need the last characters after the last '|' .. thanks (5 Replies)
Discussion started by: meghana
5 Replies

9. UNIX for Dummies Questions & Answers

Ksh Checking if string has 2 characters and does not contain digits?

How could I check if a string variable contains at least (or only) 2 characters, and check and make sure that the string does not contain any numeric digits?...I need to know how to do this as simple as possible. and I am using the Ksh shell. Thanks. (1 Reply)
Discussion started by: developncode
1 Replies

10. Shell Programming and Scripting

Print the characters in a word

Hi, How can I split the characters in a word? For Eg: If my input is: command my output should be: c o m m a n d Please help me in doing it so. (5 Replies)
Discussion started by: chella
5 Replies

Featured Tech Videos