vi or vim replace ,$ (eol) with just a comma | Unix Linux Forums | UNIX and Linux Applications

  Go Back    


UNIX and Linux Applications Discuss UNIX and Linux software applications. This includes SQL, Databases, Middleware, MOM, SOA, EDA, CEP, BI, BPM and similar topics.

vi or vim replace ,$ (eol) with just a comma

UNIX and Linux Applications


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-14-2007
dbauhaus dbauhaus is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 14 November 2007, 5:15 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old 11-14-2007
prowla prowla is offline
Read Only
 
Join Date: Nov 2007
Last Activity: 16 July 2012, 4:02 PM EDT
Posts: 165
Thanks: 0
Thanked 2 Times in 2 Posts
If you want to collapse every three lines into one, you could try:
cat myfile | paste - - -
The Following User Says Thank You to prowla For This Useful Post:
arun_maffy (05-15-2012)
Sponsored Links
    #3  
Old 11-14-2007
dbauhaus dbauhaus is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 14 November 2007, 5:15 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 11-14-2007
dbauhaus dbauhaus is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 14 November 2007, 5:15 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #5  
Old 11-14-2007
prowla prowla is offline
Read Only
 
Join Date: Nov 2007
Last Activity: 16 July 2012, 4:02 PM EDT
Posts: 165
Thanks: 0
Thanked 2 Times in 2 Posts
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
Sponsored Links
    #6  
Old 11-15-2007
kahuna's Avatar
kahuna kahuna is offline
Registered User
 
Join Date: Apr 2007
Last Activity: 1 August 2011, 7:54 AM EDT
Posts: 149
Thanks: 0
Thanked 1 Time in 1 Post
Try

Code:
g/,$/.,+2j

Sponsored Links
    #7  
Old 10-02-2008
undeadb undeadb is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 2 December 2008, 6:52 AM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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

works for me in a VIM 7.1 f/ windows <== irgh
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace newline with comma. Jotne Shell Programming and Scripting 7 01-16-2011 02:57 AM
Replace the | with Comma bharathappriyan Shell Programming and Scripting 6 11-10-2010 08:13 PM
Replace comma with newline eltinator Shell Programming and Scripting 1 02-11-2009 05:04 PM
replace comma(,) with Tab vikas_kesarwani Shell Programming and Scripting 3 11-14-2008 01:15 AM
Replace , (comma) with space mbarberis Shell Programming and Scripting 6 03-29-2005 09:35 AM



All times are GMT -4. The time now is 12:12 AM.