LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-15-2006, 03:10 AM   #1
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Rep: Reputation: 30
How to output a single character several times? (Solved)


Hi,

I need a command that lets me output a single character multiple times, so that I dont need to type that charcater myself over and over again.

I have tried to do this in a loop, but the character was put on a new line everytime and I need every character on the same line.

So with my loop this happend:

a
a
a
a

And I want it to be like:

aaaaaaaa

So want command can I use to achieve what I want?

Thanks for your help.

Regards,

Ben

Last edited by daYz; 09-15-2006 at 02:26 PM.
 
Old 09-15-2006, 04:01 AM   #2
edenyard
LQ Newbie
 
Registered: Jun 2002
Location: England
Distribution: Slackware 12.2
Posts: 6

Rep: Reputation: 0
How to output a single character several times?

If you're using a shell script to do this and using the 'echo' command, you can add the -n switch to echo to suppress the new-line character that it otherwise outputs after printing your string. Have a look at the man page for 'echo' and you'll see what I mean.

Maybe you could post a code snippet here to illustrate how you're going about the job?

Hope this helps!

Gerald.
 
Old 09-15-2006, 04:35 AM   #3
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: London, England
Distribution: Ubuntu
Posts: 1,460

Rep: Reputation: 48
If it's in a text file that you want to do it, open it with vi and type 10ia<esc> to get ten a's in a string. Alter the number & the characters to suit. . .
 
Old 09-15-2006, 04:57 AM   #4
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,596

Rep: Reputation: 80
or use the printf command

Last edited by Agrouf; 09-15-2006 at 04:59 AM.
 
Old 09-15-2006, 05:34 AM   #5
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
Woohoo!!

I have got it working. The -n switch did the job for me.

Thanks people.

Regards,

Ben
 
Old 09-15-2006, 02:24 PM   #6
daYz
Member
 
Registered: Nov 2003
Distribution: Ubuntu
Posts: 164

Original Poster
Rep: Reputation: 30
For people who wonder what code I've used, here it is:

z=0

if [ "$1" ]

then

while [ ! $z -eq "$1" ]

do echo -n a

let "z+=1"

done

else

echo Geef het aantal op

fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the ninth (9th) character or field in the output string of rpm -V ? zimon Linux - Distributions 1 08-28-2006 03:47 PM
LXer: Multi Distro is Linux times 9 on a single CD-R LXer Syndicated Linux News 0 06-03-2006 05:54 PM
System hangs; Atheros Madwifi-ping times out every 15/16 times james 456 Linux - Networking 0 01-12-2006 07:55 PM
series-Write a single shell command to display the following output ricki Programming 2 07-31-2005 04:53 PM
input single integer value, output the value as separate digits hubabuba Programming 2 03-02-2005 11:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration