tap character in vi
How do I replace the first space of each line with tap in vi?
For example, i have Name phone zip John 243-3244 44234 Tim 523-2342 55242 I want the space between Name and phone number to be replace by tap. is there an easy way in vi? |
Assuming that it's ALWAYS going to be "Name phone" then I will try...
Code:
%s/Name phone/Name tap phone/g |
I think the OP means TAB (not tap) character.
Use \t (backslash t) as the tab character. :%s/Name phone/Name\tphone/g |
Do you mean a tab character in the first space on each line? If so, start the editor then
Code:
:g/ /s//<tab>/ If you wanted to replace all (not just the first) Code:
:g/ /s//<tab>/g |
Thank you for the quick response.. I meant <tab> :)
The method from tronayne seems to work, but I want to replace only the first space of each line. How do I do that? do I have to write a script to do it? if I also want to have a index line number as well, is that a way to do it? Here is an example of output i really need. Can anyone help? 1 <tab> John <tab> 243-3244 44234 2.<tab> xxx <tab> xxx xxx |
Remove the g flag from the end of the substitution.
Here's one way to number a range of lines: Go to the first line that you want numbered. Type ma to place a Mark labeded a. Go to the last line you wanted numbered. Type !'acat -n and hit Enter. This will send all the lines between the first and current line to cat -n, replacing your output. |
Quote:
Code:
:g/ /s//<tab/ If you want to insert a <tab> at the beginning of a line Code:
:g/^/s//<tab>/ If you wanted to insert a <tab> at the end of a line, Code:
:g/$/s//<tab>/ The caret (^) stands for beginning of line, the dollar sign ($) stands for end of line. The vi editor uses regular expressions for editing; take a look at http://www.regular-expressions.info/reference.html for examples. |
Replace first space on each line:
:%s/ /<tab>/ where <tab> means hit tab key once |
All times are GMT -5. The time now is 10:37 PM. |