Shell script to print "*" pattern | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Shell script to print "*" pattern

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-17-2010
Akshayr Akshayr is offline
Registered User
 
Join Date: May 2010
Last Activity: 17 May 2010, 11:45 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Shell script to print "*" pattern

Plz tel me how to print the following pattern using shell script??


Code:
   *
  ***
 *****
*******
 *****
  ***
   *

and

Code:
    *
*********
    *

Moderator's Comments:
Use code tags please, ty.

Last edited by Akshayr; 05-17-2010 at 11:45 AM.. Reason: code tags, reformatted and added * so it is symmetrical ;)
Sponsored Links
    #2  
Old 05-17-2010
Reboot's Avatar
Reboot Reboot is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 12 July 2012, 4:30 AM EDT
Location: meri jaan Mumbai, from mera desh BHAARAT.
Posts: 147
Thanks: 7
Thanked 15 Times in 15 Posts
Use following :


Code:
echo \*
 
i.e :
echo \*
echo \***
echo \****
echo \******
echo \****
echo \***
echo \*

Sponsored Links
    #3  
Old 05-17-2010
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
 
Join Date: Jun 2003
Last Activity: 10 January 2014, 5:37 AM EST
Location: Scotland
Posts: 594
Thanks: 1
Thanked 28 Times in 27 Posts
one (bash) way:


Code:
#  for x in 1 3 5 7 5 3 1; do printf "%.$((3-$x/2))d" 0|tr "0" " ";printf "%.${x}d\n" 0|tr "0" "*"; done
   *
  ***
 *****
*******
 *****
  ***
   *

    #4  
Old 05-17-2010
pseudocoder's Avatar
pseudocoder pseudocoder is offline
Registered User
 
Join Date: Sep 2007
Last Activity: 17 February 2012, 6:42 AM EST
Location: /home/sea
Posts: 602
Thanks: 40
Thanked 83 Times in 81 Posts
Diamond long version

Code:
perl -e 'printf("%s%s\n%s%s\n%s%s\n%s\n%s%s\n%s%s\n%s%s\n"," "x3,"*"x1," "x2,"*"x3," ","*"x5,"*"x7," ","*"x5," "x2,"*"x3," "x3,"*"x1)'

Diamond short version

Code:
perl -e 'for (3,2,1,0,1,2,3) {print " "x$_."*"x(7-2*$_)."\n";}'

Division sign:

Code:
perl -e 'for (4,0,4) {print " "x$_."*"x(9-2*$_)."\n";}'

Sponsored Links
    #5  
Old 05-17-2010
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 24 July 2014, 4:49 PM EDT
Location: Amsterdam
Posts: 9,281
Thanks: 260
Thanked 2,303 Times in 2,066 Posts

Code:
cat<<EOF
   *
  ***
 *****
*******
 *****
  ***
   *
EOF

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to print range of lines using sed when pattern has special character "[" nehashine Shell Programming and Scripting 3 05-06-2010 04:13 AM
"too big" and "not enough memory" errors in shell script jerardfjay AIX 11 03-16-2009 11:09 PM
In ksh shell command - Print "-ABC" is giving error sagarjani Shell Programming and Scripting 2 10-08-2008 04:32 PM
shell script to replace a line contain an unkown pattern starting with "aaa, bbb" Dingrong UNIX for Dummies Questions & Answers 2 10-07-2008 09:06 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 12:52 AM



All times are GMT -4. The time now is 05:38 PM.