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 > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace last / by | naikaa Shell Programming and Scripting 6 01-17-2008 02:19 AM
How to replace into Vi ravi.sadani19 Shell Programming and Scripting 5 06-25-2007 09:30 AM
Replace \n with \r\n Chanakya.m Shell Programming and Scripting 3 07-19-2006 07:20 AM
How to replace using SED? mahatma Shell Programming and Scripting 4 03-23-2006 03:04 PM
Replace jda2001 UNIX for Dummies Questions & Answers 2 09-06-2005 02:20 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 04-07-2008
charandevu charandevu is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 29
replace

hi
i have input file in this format
E102|0|1-23-1994|0|12-5-1994|E003|A|10450|charan,devupalli|5000

how to convert this into outfile
E102,0,1-23-1994,0,12-5-1994,E003,A,10450,charan,devupalli,5000

i wann the output in excel sheet.........that is why i am converting into csv..
but i have the name file as firstname, lastname and it should be present in one column charan,devupalli

Pls send me asap.


thanks in advance
cherry
  #2 (permalink)  
Old 04-07-2008
charandevu charandevu is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 29
hi

$ cat > in6
E102|0|1-23-1994|0|12-5-1994|E003|A|charan,devupalli|2000
$ sed 's/|/,/g' in6 > out6.csv
$ cat out6.csv
E102,0,1-23-1994,0,12-5-1994,E003,A,charan,devupalli,2000
in the excel


in the excel i am getting charan and devupalli into two columns but i need to get in a single column like
charan,devupalli.....

thanks
cherry
  #3 (permalink)  
Old 04-07-2008
DeCoTwc DeCoTwc is offline
Registered User
  
 

Join Date: Mar 2008
Location: NYC
Posts: 74
I'm not certain I'm following what you're saying, but if I do...

Code:
cat in|tr "|" "," > out
should give you what you want. I don't think I understand why your SED statement isn't working, but tr will replace the |'s with ,'s
  #4 (permalink)  
Old 04-07-2008
charandevu charandevu is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 29
hi

Quote:
Originally Posted by DeCoTwc View Post
I'm not certain I'm following what you're saying, but if I do...

Code:
cat in|tr "|" "," > out
should give you what you want. I don't think I understand why your SED statement isn't working, but tr will replace the |'s with ,'s
i am getting the date in the excel sheet.

If i have a file like
E001|0|23/01/2007|CHARAN,DEVUPALLI|4000|INDIA| !INPUT

E001,0,23/01/2007,CHARAN,DEVUPALLI,4000,INDIA| !OUTPUT

I CAN CONVERT THE FILE BY USING SED......AND I AM GETTING THE OUT PUT.........
BUT I AM GETTING THE CHARAN IN ONE SEPARATE COLUMN AND THE DEVUPALLI IN SEPARATE COLUMN.

I NEED TO GET THE CHARAN,DEVUPALLI IN A SINGLE COULMN........HOW TO DO THAT........

PLS send how to do that
  #5 (permalink)  
Old 04-07-2008
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
echo 'E102|0|1-23-1994|0|12-5-1994|E003|A|10450|charan,devupalli|5000'| sed 's/\([^|][^|]*\)|/"\1",/g'
  #6 (permalink)  
Old 04-07-2008
ag79 ag79 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 33
dude, first, lose the caps.

second, I think your problem lies with the way u handle Excel, not in Unix. If you convert all "|" to commas, the comma becomes a delimiter and "charan,devupalli" become two seperate items, delimited by commas.

A csv file does not need to have comma as a delimiter, you can set the pipe sign as a delimiter too (Use the Tools-> Text to columns and you can set the delimiter there)

So you can use the very first line directly in excel, no need to mod it in unix. you're just going circles.
  #7 (permalink)  
Old 04-07-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
If you actually want to convert the separator to comma for unrelated reasons, you can have comma inside a field by putting it in double quotes. Different (per)versions of Excel have different bugs and conventions for how exactly they break when you try to do this, so you will have to experiment a bit.
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 08:17 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