The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Yank a column in vi stevelrf UNIX for Dummies Questions & Answers 2 04-08-2006 11:04 PM
annoying vi yank word + delete all question umen UNIX for Dummies Questions & Answers 4 03-20-2006 04:46 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-27-2003
Registered User
 

Join Date: Sep 2001
Location: Phoenix
Posts: 76
yank

This is supposed to be simple to do but I am having a hard time trying to yank 1 line (yy) but creating from it 100 lines. I can do yy then keep hitting . to repeat but it doesn't make sense. I may want to create 1000 lines from the one liner.

yy then 99 p doesn't work....

Thanks.

I was at this website ( http://www.unm.edu/~cs151/luger/references/vi.manual) after searching the forum to get an answer but it doesn't work for me ( :1,99g/^/''aco'a ) ?? What are they saying?

Gianni
Forum Sponsor
  #2 (permalink)  
Old 01-27-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,452
There isn't any great way to do this, but here what I do: I do a "yy" followed by a "p", then 8 dots. Then I move the cursor up and to a "10yy" Now each p will give me 10 lines. If that isn't enough I would just put 100 lines in the yank buffer. But 10 lines has always done it for me.
  #3 (permalink)  
Old 01-28-2003
criglerj's Avatar
Registered User
 

Join Date: May 2002
Location: Atlanta
Posts: 129
The simplest way for this is to create your one line, then run it through an external filter. With the cursor on the same line, type

!!awk ' {for(i=0;i<100;i++) print'

If you find yourself doing this a lot, type the line into your buffer this way:

!!awk ' {for(i=0;i<100;i++) print'^V^M

i.e., append a carriage return to the line. Now go to the beginning of the line and type

"dD

Now "@d" will replace whatever line you're on with 100 copies of it.
  #4 (permalink)  
Old 01-28-2003
Registered User
 

Join Date: Sep 2001
Location: Phoenix
Posts: 76
Thanks for the suggestion so far. Turns out the file I'll be working with is a huge file with 1 mil rows that I need to add 20 more columns to the end of each row. The columns to be added are all the same info. I tried experimenting with the paste command with a small file of 10 rows and it did exactly what I wanted. It appended the 10 columns to the end of each row of the first file and I thought I was smart. So I figured, okay, easiest way to add 20 more columns to this large file is to create a file with 1 mil rows of the additional columns to match the original file and then do the paste oldfile newfile > bigfile but when I couldn't duplicate the lines so easily and had to hit yy, it got to be annoying so I kind of wish I had been better at awk or something. If I want to avoid the yank case because there's no easy way to do it easily, then I may have to try criglerj solution huh?

Thanks, everyone.
  #5 (permalink)  
Old 01-28-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,452
Quote:
Originally posted by giannicello
Thanks for the suggestion so far. Turns out the file I'll be working with is a huge file with 1 mil rows that I need to add 20 more columns to the end of each row. The columns to be added are all the same info.
Yikes! Your original post was talking about 100 to 1000 lines. If you want to add the same string of characters to each of 1 million lines in a file, don't use vi. Try this:

sed 's/$/<new string of stuff goes here>/' < input > output
  #6 (permalink)  
Old 01-29-2003
Registered User
 

Join Date: Sep 2001
Location: Phoenix
Posts: 76
That was awesome! It did exactly what I wanted it to do.

Thanks. I was kind of hung up on finding a solution with paste but this is much better and quicker.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0