vi - Can vi add Characters in the range of line by command? - shell
This is a discussion on vi - Can vi add Characters in the range of line by command? - shell ; Hi Reader Can vi add Characters in the range of line by command ? e.g. original file Line 1 Line 2 Line 3 Line 4 I want add "!" at the begining of line between line 2 and line 3. ...
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| Can vi add Characters in the range of line by command ? e.g. original file Line 1 Line 2 Line 3 Line 4 I want add "!" at the begining of line between line 2 and line 3. to be Line 1 ! Line 2 ! Line 3 Line 4 |
|
#2
| |||
| |||
|
moonhk wrote: > Hi Reader > > Can vi add Characters in the range of line by command ? > > e.g. > original file > > Line 1 > Line 2 > Line 3 > Line 4 > I want add "!" at the begining of line between line 2 and line 3. > to be > Line 1 > ! Line 2 > ! Line 3 > Line 4 > :2,3 s/^/!/ but vi may not be the best tool for the job. Normally sed or awk would be the tool of choice for making bulk changes to text files: sed '2,3 s/^/!/' file awk 'NR>=2 && NR<=3{printf "!"}1' file Ed. |
|
#3
| |||
| |||
|
On 16 Mrz., 08:28, "moonhk" > Hi Reader > > Can vi add Characters in the range of line by command ? How is that range defined (by pattern, by line number, by marks)? > > e.g. > original file > > Line 1 > Line 2 > Line 3 > Line 4 > I want add "!" at the begining of line between line 2 and line 3. > to be > Line 1 > ! Line 2 > ! Line 3 > Line 4 Generally use the substitute command (:s) with an appropriate range (line numbers, patterns, marks, ...). :2,3s/^/!/ :/Line 2/,/Line 3/s/^/!/ :'a,'b s/^/!/ (The latter if you have set marks (ma, mb) at the respective lines.) Or any combination of line numbers, patterns, or marks. You can also specify the current line by using a dot in one of the range bounds. If you happen to use Vim that allows visual marks (use command V to mark, then type :s/^/!/) which will be displayed as :'<,'>s/^/!/ Janis |
![]() |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comp.sys.hp.hpux FAQ | Database Administrator | hp-hpux | 0 | 05-26-2006 12:24 AM |
| comp.sys.hp.hpux FAQ | Database Administrator | hp-hpux | 0 | 05-16-2006 12:22 AM |
| comp.sys.hp.hpux FAQ | Database Administrator | hp-hpux | 0 | 05-25-2005 12:31 AM |
| comp.sys.hp.hpux FAQ | Database Administrator | hp-hpux | 0 | 05-04-2005 12:28 AM |
| comp.sys.hp.hpux FAQ | Database Administrator | hp-hpux | 0 | 04-23-2005 12:33 AM |
All times are GMT -4. The time now is 03:29 AM.




Linear Mode
