• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VI Question

Brian07

Senior member
If I have a text file open in VI that looks like


12345
54321
21435
24135
etc.
etc.
for hundreds of lines, whats the comand I want to simply append a , to the end of every line such as

12345,
54321,
21435,
etc.

Thanks!
 
With the file open in vi, do the following:

:%s/$/,/


This will add a comma, for example, at the end of each line.
 
so your command is saying

%-globally s-search/$-end of everyline /, - append comma?

Thanks!


PS- that works but it puts a ton of spaces between the last digit and the end of line comma....

12345 ,

 
It should only append a single comma and no spaces. Maybe there was already spaces at the end of each line? Do a "set list" within the file to see if there are any trailing spaces there already.
 
Ofcourse.

Take your original file before adding your trailing comma or whatever. In the file, do
:%s/\(.*\) *$/\1/

Note: There is 2 spaces between \) and *$

After that, then add back the trailing comma or whatever. I assume you made a copy of your original file?
 
Pure magic...thanks a ton. Now if you don't mind could you briefly explain the syntax? Just for my own understanding? Thank you very much!


Brian
 
.... and i thought i know vi by heart .... 🙁 🙁

anyway, the vi lovers homepage is very good resources of everything we all oh so love 🙂

now, if only i have even the slightest motivation to read the faqs myself.... 🙁 😉

🙂🙂
-171-
 
:%s/\(.*\) *$/\1/

:%s/ / - substitute command
\(.*\) - save all the text on the line
*$ - all spaces at the end of the line
\1 - restore the line without spaces
 
Back
Top