The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > UNIX and Linux Applications
Google UNIX.COM


UNIX and Linux Applications Questions involving software not covered by other forum go here. This includes Databases and Middleware.

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 12:16 AM
sed utility to replace /307 with comma obedkhan UNIX for Dummies Questions & Answers 1 02-06-2006 07: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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-14-2007
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-14-2007
Read Only
 

Join Date: Nov 2007
Posts: 165
If you want to collapse every three lines into one, you could try:
cat myfile | paste - - -
Reply With Quote
  #3 (permalink)  
Old 11-14-2007
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
Reply With Quote
  #4 (permalink)  
Old 11-14-2007
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
Reply With Quote
  #5 (permalink)  
Old 11-14-2007
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
Reply With Quote
  #6 (permalink)  
Old 11-15-2007
kahuna's Avatar
Registered User
 

Join Date: Apr 2007
Posts: 148
Try
Code:
g/,$/.,+2j
Reply With Quote
  #7 (permalink)  
Old 1 Week Ago
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0