How to expand the same word?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to expand the same word?
# 1  
Old 12-29-2009
How to expand the same word?

Hi All,
May I know how to expand the words?
e.g:
a
aa
aaa
aaaa
I have try to use
for (i=0;i<5;i++)
do
c="a"
echo -n $c
done
but the output is aaaaa. Is it need to use array?Smilie
Thanks for your help!
# 2  
Old 12-29-2009
Using bash
Code:
# i=1;a=; while [ ${i} -lt 5 ];do a="${a}a";echo $a;let i++;done
a
aa
aaa
aaaa

# 3  
Old 12-29-2009
Code:
for ((i=1;i<5;i++));  do  for ((j=1;j<=$i;j++)); do echo -n "a"; done;  echo;done

# 4  
Old 12-29-2009
Try:

Code:
perl -e 'for ($i=0;$i++<5;) { print "a" x $i ."\n"; }'

# 5  
Old 12-29-2009
Or you can use Ruby Smilie

Code:
$
$ ruby -le '4.times{|y|print "a"*(y+1)}'
a
aa
aaa
aaaa
$

tyler_durden
# 6  
Old 12-29-2009
Hi Guys,

Really thanks for your kind help! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

How to expand three LVMs?

Hello All, It goes like this.. I have increased the data hard drive of server by 100GB and rebooted the server. I want to expand each of the LVM's by 30GB each .There are totally three LVMS to be expanded.Any help on complete commands that needs to be followed?Thanks (4 Replies)
Discussion started by: gull05
4 Replies

2. AIX

Expand LV

Under the df command, one of my logical volumes, /dev/hd4, was showing 100% Used, so I added 2 logical partitions, but its still showing 100% used. Is there a separate command I need to execute to reallocate? (5 Replies)
Discussion started by: markper
5 Replies

3. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

4. AIX

Expand LUN

Hello all, I have the following env: * DS4300 storage SAN * AIX 5.3 Lpar (storage through vio server) * AIX 5.3 Server Some FS are too small do I'm setting up a process to increase the size of the FS. To expand the size of the FS I plan to do the following for the physical AIX server,... (1 Reply)
Discussion started by: petervg
1 Replies

5. UNIX for Dummies Questions & Answers

How to expand who command?

When I do the who command it doesn't show all my info: $w gscn 6:08PM up 4 days, 20:33, 177 users, load averages: 7.46, 3.78, 3.43 USER TTY FROM LOGIN@ IDLE WHAT gscn R1 pool-92-199-17-1 5:46PM - w gscn Like in the 'From' column.... (8 Replies)
Discussion started by: guitarscn
8 Replies

6. Shell Programming and Scripting

expand and uuencode...

I have a log file that looks fine when you view it in Unix but when I send it as an attachment to myself it looses its formatting... so I am using "expand" to replace the tabs with spaces and the format looks good. The code below works great but I was wondering if there was a way to do this without... (2 Replies)
Discussion started by: sethcoop
2 Replies

7. Solaris

Expand ufs Filesystems

Hi All, I need to expand a number of Filesystems on a Sun machine running Solaris 10 OS. But first I am confused; 1. Is it possible to expand a ufs filesystem such as /dev/dsk/c1t1d0s0 (that is not managed by SVM) without lossing existing data? 2. Is it possible to have such a... (7 Replies)
Discussion started by: atogunde
7 Replies

8. Shell Programming and Scripting

expand logic for > and <

Hi Input A12345678901234567890 < A12345678901234567890 AND C12345678901234567890 < D12345678901234567890 AND E12345678901234567890 > F12345678901234567890 If the length of the line at any point exceed more than 60 chars it should come to next line but it should not break a variable... (0 Replies)
Discussion started by: pbsrinivas
0 Replies

9. UNIX for Advanced & Expert Users

Terminal Expand

hi guys. i have written a script/program and i would strongly prefer if this script automatically expands the user's terminal whenever he or she starts the script. this is so the script/program can fit on the user's screeen without user having to manually drag and spread his screen. what... (2 Replies)
Discussion started by: Terrible
2 Replies
Login or Register to Ask a Question