Operating System - HP-UX
1825355 Members
4070 Online
109679 Solutions
New Discussion юеВ

Copy a line 10 times with vi in HP-UX

 
Dipu
Occasional Advisor

Copy a line 10 times with vi in HP-UX

Hi,
I tried to yank a line using "yy" and tried to paste the same 10 times by using "10P". But the line got pasted only once.

In a similar way I tried to copy the line using "y$" and tried to paste it 10 times using "10P". This worked fine.

But in the second case, the line copied was pasted in the same line.
But I want this to happen in multiple lines.

Can any one suggest any other method other than using vi for duplicating a file containing one line 10 times.
15 REPLIES 15
Paula J Frazer-Campbell
Honored Contributor

Re: Copy a line 10 times with vi in HP-UX

Hi

Try

yy
10pp

Paula
If you can spell SysAdmin then you is one - anon
James R. Ferguson
Acclaimed Contributor

Re: Copy a line 10 times with vi in HP-UX

Hi:

# awk '{for (i=0;i<10;i++) print $0}' infile > outfile

Regards!

...JRF...
Leif Halvarsson_2
Honored Contributor

Re: Copy a line 10 times with vi in HP-UX

Hi,
It is very easy if you run CDE.

Open the file with dtpad ,mark the line with left mouse button and copy with middle mouse button.

It is also possible to use this method with vi.
Vicente Sanchez_3
Respected Contributor

Re: Copy a line 10 times with vi in HP-UX

Hello,

Try this:

line=$(cat file_with_line)
for i in 0 1 2 3 4 5 6 7 8 9
do
echo $line >>new_file
done
HTH, Vicente.

Ian Dennison_1
Honored Contributor

Re: Copy a line 10 times with vi in HP-UX

Multi ways of doing this,...

[Position on Line]
Y P
2Y P
4Y P
2Y P

Makes 10 lines. I tend to use the simple approach for things like this,..

Y P P P P P P P P P

Share and Enjoy! Ian
Building a dumber user
Dipu
Occasional Advisor

Re: Copy a line 10 times with vi in HP-UX

Hi,
Paula, your solution did not work. It just prints the line 2 times as you mentioned pp.

James, Thanks a lot for that alternate suggesion. But can you also suggest me a solution by using vi. As none of the solution I recieved seems to work fine.

Leif, I don't wish to do a manual work for copying.

Regards!
Dipu
James R. Ferguson
Acclaimed Contributor

Re: Copy a line 10 times with vi in HP-UX

Hi (again):

Well, you asked for "..any other method other than using vi..." so I offered 'awk'.

In 'vi' do:

yy
p
.

...where the "." is a repetition of the 'p'ut, so you type "." eight times to yield a total of ten identical lines in the file. Simple and fast!

Regards!

...JRF...
Dipu
Occasional Advisor

Re: Copy a line 10 times with vi in HP-UX

Hi James,
Repeating . 10 times will do. But suppose I want to generalize to 1000 times it's difficult. So I want a direct method.

Your awk method really solved my problem. But out of curiosity I would like to know whether this is possible with vi.

Thanks a lot

Regards!!!
Dipu

Geoff Wild
Honored Contributor

Re: Copy a line 10 times with vi in HP-UX

Yes - just do:

10yy
p

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Donny Jekels
Respected Contributor

Re: Copy a line 10 times with vi in HP-UX

in vi,

10yy

then move where you want to paste the lines.

p

done
"Vision, is the art of seeing the invisible"
Jean-Louis Phelix
Honored Contributor

Re: Copy a line 10 times with vi in HP-UX

Hi,

Quite hard ... I can only do it using this command on the line to be duplicated :

!!awk '{while (i < 10) {print ; i++}}'

Only the first ! will be displayed and you will have 10 times the original line in you current file.

It can be put in a map (while Ypppppppppp can't)

:map v !!awk '{while (i < 10) {print ; i++}}'^M

hiting v in vi will duplicate 10 times current line.

Regards.
It works for me (┬й Bill McNAMARA ...)
Umapathy S
Honored Contributor

Re: Copy a line 10 times with vi in HP-UX

Dipu,
Paula's suggestion will work with vim.
I do most of the repeating stuff like what JRF has suggested second time.
I prefer to use vim than vi.
If you really want to automate the repetition n no. of times then awk is the best solution.

HTH
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Graham Cameron_1
Honored Contributor

Re: Copy a line 10 times with vi in HP-UX



Most commands accept a preceding number as an argument, either to give a size or position (for display or movement commands), or as a repeat count (for commands that change text).


Looks like P and p are not in the list of "most commands". Too bad.

Not only that...

. Repeat the last command that changed the buffer. If a count is specified, the command is repeated the specified number of times.


But the following doesn't do that
Y
P
9.

The "9." just does it once!
Looks like we all learned something today.

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
RolandH
Honored Contributor

Re: Copy a line 10 times with vi in HP-UX

copy the line what you want to have 1000 times with
yy

Got to the line where you want to place it and hit
p

And now (if you need 1000 times this line) 1000.

That's it



Roland

Feel free to assign points
Sometimes you lose and sometimes the others win
Basheer_2
Trusted Contributor

Re: Copy a line 10 times with vi in HP-UX

Go to the starting line.

Shift Double Quote
x
1000 yy

This will put 1000 lines into register x

Now go to where you want to copy

Shift Double Quote xp

For Shift Double
(Hold down the Shift Key, Hit the '" key)