print "*" entire line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting print "*" entire line
# 1  
Old 03-25-2010
print "*" entire line

Hi folks,

I want to display the "*" character the entire line. Instead of manually giving "*" multiple times in echo/print command, i want some short cut.

i remember i have came across a straight forward method to display particular character (for example "*" ) for n number of times in unix. but now i forgot the exact source of information.

please help me.
# 2  
Old 03-25-2010
Code:
$ x=4
$ printf "%${x}s\n" " " | tr ' ' '*'
****
$ x=10
$ printf "%${x}s\n" " " | tr ' ' '*'
**********

# 3  
Old 03-25-2010
Tools Perhaps this link in our forums?

Check out this discussion
https://www.unix.com/shell-programmin...er-printf.html
# 4  
Old 03-25-2010
A basic shell loop to generate exactly ${MAX} asterisks in a shell variable called ${STRING}.

Code:
#!/bin/ksh
COUNTER=0
MAX=10
STRING=""
while true
do
        COUNTER=`expr ${COUNTER} + 1`
        STRING="${STRING}*"
        if [ ${COUNTER} -ge ${MAX} ]
        then
                break
        fi
done
echo "${STRING}"

**********



Ps. I like anbu23's ingenious use of "tr".

Last edited by pludi; 03-26-2010 at 06:11 AM..
# 5  
Old 03-26-2010
Code:
perl -le 'print "*" x 80';
********************************************************************************

Very simple in perl .. Change the number accordingly.
# 6  
Old 03-26-2010
if you have python
Code:
python -c 'print 80*"*"'

# 7  
Old 03-26-2010

Bash:
Code:
printf -v aster "%${COLUMNS}s" " "
printf "%s\n" "${aster// /*}"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

3. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

4. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

5. UNIX for Dummies Questions & Answers

use cut or awk to print line after "/bin"

Hello all, i am trying to use cut or awk to make my below lines to From $ ps -ef|grep tns|grep -v grep |grep LISTENER_TEST|awk '{print $9}' /oracle/ORAHOME/test/112/bin/tnslsnr to /oracle/ORAHOME/test/112 how can this be achieved ? so basically anything before "/bin" (3 Replies)
Discussion started by: abdul.irfan2
3 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. Shell Programming and Scripting

Accessing entire line during "while read"

I am using the time-honored construct "while read field1 field2 field3 ; do" to pull delimited fields from lines of data in a file, but there are a few places within the loop where I need to manipulate the entire, unsplit line of data. Does "while read" keep each entire record/line somewhere prior... (2 Replies)
Discussion started by: fitzwilliam
2 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question