How to add a perticular string in a file via VI editor
i have a file with 500 lines i need to add a particular string in starting/end/anywhere of each and every line of this file.
example data 123 1234123 124324 1243254523 124235423 I need to add "a" in front of every line. outcome data. a123 a1234123 a124324 a1243254523 a124235423 this needs to do only by Vi editor. we can do it by awk but how to perform the same in Vi editing. how can i do this. Please help. Regards, Prabhat |
Quote:
You might want to include examples (before/after). BTW: Wouldn't sed or awk be a better choice to do this task? |
In command mode you can do the following:
Code:
:%s/^/a/ The % tells vi to do the changes on all lines (you can also give a range instead 4,10 -> lines 4 to 10) The s/^/a/ tells vi to insert an a, at the beginning of the line (the ^). As you might have noticed this looks like the way sed does things (both use the ed command under the hood). Also have a look here: BTW: Don't edit your original post after an answer was given, post a new entry instead. If you don't there is a big chance your changes will not be noticed (we do get an e-mail when someone post a new entry, not when someone edits an already existing one). |
All times are GMT -5. The time now is 12:48 AM. |