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

$ 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

I'm not certain I'm following what you're saying, but if I do...

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

echo 'E102|0|1-23-1994|0|12-5-1994|E003|A|10450|charan,devupalli|5000'| sed 's/\([^|][^|]*\)|/"\1",/g'

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.

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.