any idea to repeat a action in VI


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers any idea to repeat a action in VI
# 1  
Old 11-21-2003
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  
Old 11-21-2003
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
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  
Old 11-25-2003
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  
Old 11-25-2003
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  
Old 11-26-2003
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  
Old 11-26-2003
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).
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to Repeat history command?

Assume i have typed 4 commands in the past like vi `ls -t |head -n 1` tail -2 test.txt ls -lrt | grep "/etc/profile.d" pwd Now if i type r p it should execute the command "pwd" likewise r t should execute tail -2 test.txt. Note: esc k and using up arrow and down arrow will get this work... (3 Replies)
Discussion started by: Ramanareddygv
3 Replies

2. Programming

Java: Repeat a command

I came across a site to learn java and they give you practice problems to do. I was wondering if anyone can help me with this since I am totally new to Java. Here is the first problem: Write a program that will read in a name from the command line and write it out 100 times. Thank you for any... (10 Replies)
Discussion started by: totoro125
10 Replies

3. Shell Programming and Scripting

Repeat for different variable

Hey, I've created following script: var1=test1 setA=testA if ... touch $setA/$var1 ... fi I would like now the repeat the command touch (in this example) for different variables. So below, the varX should run 3 times (var1, var2, var4). Var3 is skipped in this example... (4 Replies)
Discussion started by: brononius
4 Replies

4. Shell Programming and Scripting

Ping and repeat ?

How do i write a loop ping to see if it get timeout or hang ? it should loop every 30 second to ping a server ? ping -c 5 -t 15 www.google.com if ]; then date '+%Y-%m-%d %H:%M:%S Connection Unavailable' >> /home/sabercats/checkconnection.log else date '+%Y-%m-%d %H:%M:%S Connection... (3 Replies)
Discussion started by: sabercats
3 Replies

5. Shell Programming and Scripting

Repeat using for loop

I have a file like this 2011-10-10 10:46:00,1-1-13-1-1,151510,ALCLA0A84D2C 2011-10-10 10:46:00,1-1-13-1-1,151520,65537 2011-10-10 10:46:00,1-1-13-1-1,151515,46932 2011-10-10 10:46:00,1-1-13-1-1,151521,32769 2011-10-10 10:46:00,1-1-13-1-1,151522,32769 2011-10-10... (4 Replies)
Discussion started by: LavanyaP
4 Replies

6. Shell Programming and Scripting

getopts with repeat of same option

Hello, Does getopts have some way of handling the use of an option that requires a parameter more than once on the command line. e.g. mycmd -a john -a jane I came up with a solution using arrays (shown below), but wonder if getopts has some other way of handling it. Other solutions... (2 Replies)
Discussion started by: CarlosNC
2 Replies

7. UNIX for Dummies Questions & Answers

repeat each record n times

I have: aa01 aa02 aa03 aa04 ab01 ab02 ab03 ab04 I would like each record printed 5 times: aa01 aa01 aa01 aa01 aa01 aa02 aa02 (6 Replies)
Discussion started by: kenneth.mcbride
6 Replies

8. Shell Programming and Scripting

to copy and repeat

Hi All, I have done some looking at other threads but haven't found quite what I am looking for. I am a newbie to scripting and haven't got to where I want to you but here is my basic question. I have a script to copy a file and send it to another file with a date and time stamp. What I want to... (4 Replies)
Discussion started by: falcondown01
4 Replies

9. Shell Programming and Scripting

Limitations of awk? Good idea? Bad idea?

Keeping in mind that I'm relatively comfortable with programming in general but very new to unix and korn/bourne shell scripts.. I'm using awk on a CSV file, and then performing calculations and operations on specific fields within specific records. The CSV file I'm working with has about 600... (2 Replies)
Discussion started by: yongho
2 Replies

10. UNIX for Dummies Questions & Answers

Repeat Commands

On my system I use Escape "k" to go back in commands. I read on tutorials that it is ctrl p, but that does not work on my system. Anyone know what the command to go foward is? (6 Replies)
Discussion started by: dereckbc
6 Replies
Login or Register to Ask a Question