LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   vi editor - how to delete a character in each row of a column? (https://www.linuxquestions.org/questions/linux-newbie-8/vi-editor-how-to-delete-a-character-in-each-row-of-a-column-521658/)

flipwhy 01-22-2007 06:43 AM

vi editor - how to delete a character in each row of a column?
 
I'd like to delete a negative sign from each number in a particular column for say a hundred rows in vi. How d oyou do that without manually deleting all of them?

zulfilee 01-22-2007 07:03 AM

Either use substitute or a macro [I guess u are using vim,u can try the same for vi but am not sure if it works]

Suppose you have the number in the third column

:map K 2wxj
[Means Move 2words - 2w , delete the first character x , and go to next line j]
After this just press on the K key continuosly for the task to be done.

Try this too

:map K 2wxjK

This will recurse and u will have to interrupt when it reaches the last few lines.

Substitute needs regex search and replace in the format
:% substitute /patter/replace/g

If u are still not able to do the task ,paste a part of file in this post.

- zulfi

raskin 01-22-2007 07:04 AM

ctrl-v
99j
x

(I hope there are no positive numbers)

:.,.+99s/^-//

(Works anyway)

Quakeboy02 01-22-2007 07:06 AM

I'd use this as a starting point on a file that you have backed up. You may have to make some special effort since it's a negative sign. IOW, you may have to use "\-" instead of "-" (quotes not included in command). I'd have to mess with it to make sure. I'll leave that part to you. :)
Code:

:1,100s/-//g

flipwhy 01-22-2007 10:04 AM

the map K method doesnt work at all. Im not sure of how to make macros.
the 1,100s method works but it removes all negatives. How do you get it to do just one column?

raskin 01-22-2007 10:33 AM

Put caret ( ^ ) before minus ( - ). It matches only the beginning of the line.

Quakeboy02 01-22-2007 02:12 PM

"How do you get it to do just one column?"

Sorry. I missed the part that you wanted just one column changed. Can't help.


All times are GMT -5. The time now is 02:51 AM.