LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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

Reply
 
Search this Thread
Old 01-22-2007, 06:43 AM   #1
flipwhy
Member
 
Registered: Jul 2006
Posts: 102

Rep: Reputation: 15
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?
 
Old 01-22-2007, 07:03 AM   #2
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
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
 
Old 01-22-2007, 07:04 AM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
ctrl-v
99j
x

(I hope there are no positive numbers)

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

(Works anyway)
 
Old 01-22-2007, 07:06 AM   #4
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,245

Rep: Reputation: 121Reputation: 121
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
 
Old 01-22-2007, 10:04 AM   #5
flipwhy
Member
 
Registered: Jul 2006
Posts: 102

Original Poster
Rep: Reputation: 15
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?
 
Old 01-22-2007, 10:33 AM   #6
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
Put caret ( ^ ) before minus ( - ). It matches only the beginning of the line.
 
Old 01-22-2007, 02:12 PM   #7
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,245

Rep: Reputation: 121Reputation: 121
"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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to delete different column in a file? Tuku Programming 3 01-04-2007 09:53 AM
Delete the first row from a text file loopoo Linux - Newbie 2 08-15-2006 02:57 AM
Transposing a column into a row mayyash Linux - General 1 09-30-2005 02:23 AM
How to delete a column in MySQL ? indian Linux - General 2 10-15-2004 01:02 PM
How to write the contents of a column as a row in linux markraem Linux - Software 4 07-17-2004 07:35 PM


All times are GMT -5. The time now is 03:32 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration