MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
November
Sun Mon Tue Wed Thu Fri Sat
         
7
2013
Months
Nov


Thu, Nov 07, 2013 8:15 pm

Replacing a character with a newline character using vi

If you wish to replace all occurrences of a character with a newline character, which is used on Linux/Unix systems to indicate the start of a new line, you can represent the new line with a \r in a vi command; think of the "r" as representing a carriage return. E.g., if I had a long line with items on the line separated by commas, I could use the command below to remove each comma and start another line where the comma occurred, instead.

:s/,/\r/g

[/editors/vi] permanent link

Thu, Nov 07, 2013 7:54 pm

Sorting lines in a file using the vi editor

If you need to sort all the lines in a file alphabetically with the vi editor, you can use ! sort. E.g., you could sort lines 10 to 20 with the following command:

:10,20 ! sort

You can sort all lines in the file with 1,$ ! sort.

[/editors/vi] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo