![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX and Linux Applications Questions involving software not covered by other forum go here. This includes Databases and Middleware. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Comma seperator | premar | Shell Programming and Scripting | 6 | 02-17-2006 01:16 AM |
| sed utility to replace /307 with comma | obedkhan | UNIX for Dummies Questions & Answers | 1 | 02-06-2006 08:24 PM |
| Replace , (comma) with space | mbarberis | Shell Programming and Scripting | 6 | 03-29-2005 07:35 AM |
| add comma | alisevA3 | UNIX for Dummies Questions & Answers | 3 | 10-18-2002 06:29 AM |
| Add a comma at end of every line | ST2000 | Shell Programming and Scripting | 4 | 07-14-2002 03:49 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
vi or vim replace ,$ (eol) with just a comma
I have lines in a file like this (140,000+ entries):
value1, value2, value3, " " I want to concatenate the three (there are 22) lines with commas so it looks like this value1, value2, value3 " " I'm trying with :g/,$/s/,$/, /g but that is not flying. any ideas? Thanks, Dan |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
If you want to collapse every three lines into one, you could try:
cat myfile | paste - - - |
|
#3
|
|||
|
|||
|
vi or vim replace ,$ (eol) with just a comma
Unfortunately, it is a variable number of items 22-41. So I need to remove the end of line for every line that has a comma. Thanks for the thought though. -Dan
|
|
#4
|
|||
|
|||
|
Re: vi or vim replace ,$ (eol) with just a comma
Weeellllll, ok MS Word lets you replace comma + ^013 which takes a comma plus the carriage returns/line feeds/^M and leave just the comma and concatenates any line which had previously a comma (or any other character) and a new line. Sure takes a long time, and much CPU. At least it works.
Would still like to know how to do this in vi or vim, as I remember needing this before. Thanks, Dan |
|
#5
|
|||
|
|||
|
I know there's an example of something like it in the sed & awk book.
But this will work from the command line: cat myfile | while read s do case "$s" in *,) printf "%s" s;; *) echo $s;; esac done |
|
#6
|
||||
|
||||
|
Try
Code:
g/,$/.,+2j |
|
#7
|
|||
|
|||
|
I know the Thread is kind of old already, but for who might get this page in a search, here is a other fast alternative:
Code:
:%s/,\n/,/g |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|