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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-21-2003
myelvis myelvis is offline
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 .
  #2 (permalink)  
Old 11-21-2003
jsilva's Avatar
jsilva jsilva is offline
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 (permalink)  
Old 11-21-2003
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
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.
  #4 (permalink)  
Old 11-25-2003
myelvis myelvis is offline
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
  #5 (permalink)  
Old 11-25-2003
linuxpenguin's Avatar
linuxpenguin linuxpenguin is offline Forum Advisor  
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.
  #6 (permalink)  
Old 11-26-2003
tikual tikual is offline
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
  #7 (permalink)  
Old 11-26-2003
tikual tikual is offline
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).
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0