vi editor - how to delete a character in each row of a column?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.