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
repeat pattern without using excel ajp7701 Shell Programming and Scripting 3 03-14-2008 09:28 PM
Repeat last entered command ? vilius Shell Programming and Scripting 5 09-25-2007 03:15 AM
to copy and repeat falcondown01 Shell Programming and Scripting 4 09-07-2007 05:15 PM
Limitations of awk? Good idea? Bad idea? yongho Shell Programming and Scripting 2 06-08-2005 02:18 PM
Repeat Commands dereckbc UNIX for Dummies Questions & Answers 6 01-04-2005 08:15 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-21-2003
Registered User
 

Join Date: Nov 2003
Posts: 16
any idea to repeat a action in VI

Any idea to repeat an action to all the lines in vi...

suppose i want to delete the first word from all the lines in VI .. how would i do it ?

in general i am also looking for a way to apply a action to all the lines in VI .
__________________
If u r not confused today , u r not thinking clearly!!!
Forum Sponsor
  #2  
Old 11-21-2003
jsilva's Avatar
Registered User
 

Join Date: Apr 2003
Posts: 169
Hi,

If you want to repeat an action, you use the . (dot)...

Check this out for more !
http://csep1.phy.ornl.gov/unix_guide...00000000000000
  #3  
Old 11-21-2003
Kelam_Magnus's Avatar
Registered User
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
I know that you can use the "." period for repeating the same action...

If you use the dw command in vi to remove a word, then use "." it will repeat the action. then navigate down with the j key.



If you have 9 or less columns in a file awk will work great...


awk '{ print $2, $3, $4, $5, $6, $7, $8, $9 }' < file.in > file.out


If you have lines of text with more than 9 fields. I cant think of a way to do it for the whole file without calling a program from the :sh prompt.
__________________
My brain is your brain
  #4  
Old 11-25-2003
Registered User
 

Join Date: Nov 2003
Posts: 16
Any idea to apply the same action to the multiple lines in a one go ... Suppose i delete 2 words from a line and want to repeat the same action to the next 1000 lines in a one go ???


Thanks
__________________
If u r not confused today , u r not thinking clearly!!!
  #5  
Old 11-25-2003
linuxpenguin's Avatar
Registered User
 

Join Date: May 2002
Location: India
Posts: 295
Hi,

vi is a very powerful tool. explore it

to do something over a number of lines you need to use

:<startline>,<endline> command

besides this vim provides recording.

however, i wud suggest you that try to use some external scripts like awk, sed etc to do such things.
__________________
War doesnt determine who is right, it determines who is left
  #6  
Old 11-26-2003
Registered User
 

Join Date: Nov 2003
Location: HK
Posts: 53
Q1:

Example1:
cat testfile
111 222 333 444
aaa bbb ccc ddd
111 222 333 444

In vi mode, step to remove first word.
press 'Esc'
: prompt appear
then type
%s/.[^ ]* *//
"%" is represented to whole document

Example2:
cat testfile
111 222 333 444
aaa bbb ccc ddd
111 222 333 444

In vi, step to remove lines selectively
__________________
tikual :)
  #7  
Old 11-26-2003
Registered User
 

Join Date: Nov 2003
Location: HK
Posts: 53
oh sorry, press wrong key to post the previous message.

The remains are shown as follows:

press 'Esc'
: prompt appear
then type
.,1000s/.[^ ]* .[^ ]* //

it will remove first two words of each line from "current line to line 1000"(.,1000).
__________________
tikual :)
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:42 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 Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0