How to remove space and delimit a csv file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove space and delimit a csv file?
# 1  
Old 10-25-2013
How to remove space and delimit a csv file?

Hi All ,

I am facing a small challenge i need unix command to remove space as well as replace "|" to "," in a csv file .

original file :
Code:
A | B | c | D
E | F | G | H
I | J  | K | L 
P | M | N | O

Expected o/p:
Code:
A,B,c,D
E,F,G,H
I,J,K,L 
P,M,N,O


Last edited by Scrutinizer; 10-25-2013 at 03:36 AM.. Reason: code tags
# 2  
Old 10-25-2013
sed substitution

Code:
sed 's/ | /,/g' infile

# 3  
Old 10-25-2013
Try:
Code:
awk '{$1=$1; gsub(/\|/,",")}1' OFS= file

Code:
$ cat file
A | B | c |D        
E |F | G | H
I | J  | K | L 
P | M |   N | O   
$
$ awk '{$1=$1; gsub(/\|/,",")}1' OFS= file
A,B,c,D
E,F,G,H
I,J,K,L
P,M,N,O


Last edited by Scrutinizer; 10-25-2013 at 03:53 AM..
# 4  
Old 10-25-2013
You may Try

Code:
$ cat <<eof | sed "s/[[:space:]]//g;s/|/,/g"
A | B | c | D
E | F | G | H
I | J  | K | L 
P | M | N | O
eof

A,B,c,D
E,F,G,H
I,J,K,L
P,M,N,O

# 5  
Old 10-25-2013
Thank you sooooooooooooooo much all of you for the immediate response SmilieSmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to convert space&tab delimited file to CSV?

Hello, I have a text file with space and tab (mixed) delimited file and need to convert into CSV. # cat test.txt /dev/rmt/tsmmt32 HP Ultrium 6-SCSI J3LZ 50:03:08:c0:02:72:c0:b5 F00272C0B5 0/0/6/1/1.145.17.255.0.0.0 /dev/rmt/c102t0d0BEST /dev/rmt/tsmmt37 ... (6 Replies)
Discussion started by: prvnrk
6 Replies

2. Shell Programming and Scripting

How to remove space from each record in file?

Hi , I want to remove space from each record in one file My file is like BUD, BDL ABC, DDD, ABC ABC, DDD, DDD, KKK The o/p should be BUD,BDL ABC,DDD,ABC ABC,DDD,DDD,KKK Can any one help me regarding this? (9 Replies)
Discussion started by: jagdishrout
9 Replies

3. Shell Programming and Scripting

need to save the space when converting to CSV file

Hi, I have a text file with the following format. Some of the fields are blank. 1234 3456 23 45464 327837283232 343434 5654353 34 34343 3434345 434242 .... .... .... I need to convert this file to a CSV file, like 1234, ,23, ... (3 Replies)
Discussion started by: wintersnow2011
3 Replies

4. Shell Programming and Scripting

Need to remove some value in CSV file

Hi All A .csv file containing multiple value on it. i need to remove some value from it. Please advise how can i find multiple value from that and remove itself. Please provide solution for this. Thanks in advance. (4 Replies)
Discussion started by: yash1978
4 Replies

5. Shell Programming and Scripting

Remove space in whole file -perl

Hi all, I have a file which have say about 123,000 records, the records in it look like: 1294160401681,05-01-2011 00:00:01,68,Cjw,2,3333,7,1100,900,SUCCESS,200,68,localhost, 1294160406515,05-01-2011 00:00:06,68,Cjw,2,0207,7,1100,900,SUCCESS,200,68,localhost, 1294160410097,05-01-2011... (3 Replies)
Discussion started by: danihamdani
3 Replies

6. UNIX for Dummies Questions & Answers

Space in file how to remove

Hello I have a file with data something like this in it : texttexttext "text .lst" TEXT=" text " texttexttext "moretext .lst" TEXT=" text " Question is how do I get rid of space so that the files looks like this : texttexttext "text.lst" TEXT="text" texttexttext... (8 Replies)
Discussion started by: davebw
8 Replies

7. Shell Programming and Scripting

remove space from file content

i am a bit new to shell scripting i have a file containing xxxx xx xx but i want to output the content as xxxxxxxx. thus removing the space. any idea how i can do this (4 Replies)
Discussion started by: blackzinga
4 Replies

8. Shell Programming and Scripting

Blank Space is not appending in each row of CSV File - Shell Script

I am calling SQL script in my UNIX Shell script and trying to create the CSV file and my last column value of each row is 23 blank spaces. In my SQL script,the last column is like below. RPAD(' ',23,' ') -- Padding 23 blank Spaces The CSV file is generated but the sapce(23 spaces) is... (2 Replies)
Discussion started by: praka
2 Replies

9. Shell Programming and Scripting

cat or cut to delimit csv?

Hi, Im a pretty large noob to linux/perl etc and im trying to use mysql slurp to take a delimited file and import it into mysql using stdin (in the hope its faster) mysqlslurp - slurp <STDIN> into a MySQL table - search.cpan.org Christopher Brown / MySQL-Slurp - search.cpan.org Using... (3 Replies)
Discussion started by: newtony
3 Replies

10. UNIX for Dummies Questions & Answers

to remove space in a txt file

I want to fetch text after the first occurance of the word "started at" i.e. consider a text written below... echo 'hi how r u ' Started at MON Jan 11 00:03:24 EST 2009 echo 'hi how is ur job goin on' Started at Sun Jan 11 00:03:24 EST 2004 Started at TUE Jan 11 00:03:24 EST 2005 Started... (19 Replies)
Discussion started by: manit
19 Replies
Login or Register to Ask a Question