Print String N times the number before it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print String N times the number before it
# 8  
Old 01-31-2015
Hi.

To avoid explicit coding for loops:
Code:
$ yes "a b c" | head -n 20 | column
a b c	a b c	a b c	a b c	a b c	a b c	a b c	a b c	a b c	a b c
a b c	a b c	a b c	a b c	a b c	a b c	a b c	a b c	a b c	a b c

For systems like:
Code:
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian 5.0.8 (lenny, workstation) 
yes (GNU coreutils) 6.10
head (GNU coreutils) 6.10
column - ( /usr/bin/column, 2007-11-20 )

Best wishes ... cheers, drl
These 2 Users Gave Thanks to drl For This Post:
# 9  
Old 02-01-2015
For a single word, try :
Code:
echo "20 hello" | perl -ane 'print (($F[1]."\n") x $F[0])'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print number of lines for files in directory, also print number of unique lines

I have a directory of files, I can show the number of lines in each file and order them from lowest to highest with: wc -l *|sort 15263 Image.txt 16401 reference.txt 40459 richtexteditor.txt How can I also print the number of unique lines in each file? 15263 1401 Image.txt 16401... (15 Replies)
Discussion started by: spacegoose
15 Replies

2. Shell Programming and Scripting

How to print a particular character n number of times in a line??

hi, Is it possible to print a particular character n number of times in a line? for example. i am print the following line using echo command.. echo "files successfully moved" i want to count the number of characters that are been displayed. i am doin it using echo "files... (8 Replies)
Discussion started by: Little
8 Replies

3. Shell Programming and Scripting

Print each column 3 times

Hi All, I have a file with more than 2000 columns and I would like to print each column 3 times, so that I will get a file like col1 col1 col1 col2 col2 col2 ........coln coln coln. I have tried the following code: awk '{for(i=1; i<=NF; i++) {s=s FS $i,$i,$i} print s;s=""}' input >... (2 Replies)
Discussion started by: Fredrick
2 Replies

4. Shell Programming and Scripting

find string nth occurrence in file and print line number

Hi I have requirement to find nth occurrence in a file and capture data from with in lines (between lines) Data in File. <QUOTE> <SESSION> <ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/> <ATTRIBUTE NAME='Service Name' VALUE='None'/> </SESSION> <SESSION> <ATTRIBUTE... (6 Replies)
Discussion started by: tmalik79
6 Replies

5. Programming

Find and print number after string in C

I'm trying find and print a number after a specific user passed string in each line of a text file using C (as requested by the powers that be). I've pieced together enough to read the file, find the string and print the line it was found on but I’m not sure where to even start in terms of finding... (3 Replies)
Discussion started by: cgol
3 Replies

6. Shell Programming and Scripting

Print a word specific number of times

Hi All, I wanted to know if there is a shell command to print a word n number of times The Input File is : Cat 4 Bat 3 Zall 1 Kite 2 Output File required is : Cat Cat Cat Cat Bat Bat Bat Zall Kite (4 Replies)
Discussion started by: sam_2921
4 Replies

7. Shell Programming and Scripting

How to print the number of lines from a file, the starting string should be passed`

Hi , I have file, which has the below content: line 100 a b c d line300 a s d f s line200 a s d a (3 Replies)
Discussion started by: little_wonder
3 Replies

8. Shell Programming and Scripting

way to print all the string till we get a space and a number

Is there any way to print all the string till we get a space and a number and store it a variable for eg we have string java.io.IOException: An existing connection was forcibly closed by the remote host 12 All I want is to store "java.io.IOException: An existing connection was forcibly closed... (13 Replies)
Discussion started by: villain41
13 Replies

9. Shell Programming and Scripting

printing strings in one X number of times from another

I have one file of numbers 4 5 2 ... And another file of strings aaaaa bbbbb ccccc ddddd eeeee ffffff ... I'd like to print the stings from each line in reverse order with some decoration the number of times listed in the first file such as: Yeah bbbbb aaaaa Yeah bbbbb aaaaa (5 Replies)
Discussion started by: dcfargo
5 Replies

10. AIX

Number of login times

Hi! I'm currently using AIX 4.3 and would like to know where can i find to see that there's a restriction on the number of login times a user can have. Example, I want to see whether user A has only 1 login while user B can have 2 logins (without logging off the first one). Would I be able to... (7 Replies)
Discussion started by: ftengcheng
7 Replies
Login or Register to Ask a Question