The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > UNIX and Linux Applications
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Comma seperator premar Shell Programming and Scripting 6 02-17-2006 04:16 AM
sed utility to replace /307 with comma obedkhan UNIX for Dummies Questions & Answers 1 02-06-2006 11:24 PM
Replace , (comma) with space mbarberis Shell Programming and Scripting 6 03-29-2005 10:35 AM
add comma alisevA3 UNIX for Dummies Questions & Answers 3 10-18-2002 09:29 AM
Add a comma at end of every line ST2000 Shell Programming and Scripting 4 07-14-2002 06:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-14-2007
dbauhaus dbauhaus is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 3
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
  #2 (permalink)  
Old 11-14-2007
prowla prowla is offline
Read Only
  
 

Join Date: Nov 2007
Posts: 165
If you want to collapse every three lines into one, you could try:
cat myfile | paste - - -
  #3 (permalink)  
Old 11-14-2007
dbauhaus dbauhaus is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 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 (permalink)  
Old 11-14-2007
dbauhaus dbauhaus is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 3
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 (permalink)  
Old 11-14-2007
prowla prowla is offline
Read Only
  
 

Join Date: Nov 2007
Posts: 165
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 (permalink)  
Old 11-15-2007
kahuna's Avatar
kahuna kahuna is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 149
Try
Code:
g/,$/.,+2j
  #7 (permalink)  
Old 10-02-2008
undeadb undeadb is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 1
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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0