Insert comma in place of column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert comma in place of column
# 1  
Old 08-13-2012
Insert comma in place of column

Hi all,

I have a file in which I have to insert commna between entries of 2 column and createa new file separated by commas not a columns

if input is

Code:

FHIT     Adenosine Monotungstate    Not Available

CS     Trifluoroacetonyl Coenzyme A    Not Available  




Theo expected output is
Code:

FHIT,Adenosine Monotungstate ,Not Available
    
CS ,Trifluoroacetonyl Coenzyme A ,Not Available  



Kindly let me know scripting regarding this
body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: "Liberation Sans"; font-size: x-small; }
# 2  
Old 08-13-2012
Try this:
Code:
$ cat t
FHIT     Adenosine Monotungstate    Not Available
CS     Trifluoroacetonyl Coenzyme A    Not Available

$ sed 's/ \{2,\}/,/g' t
FHIT,Adenosine Monotungstate,Not Available
CS,Trifluoroacetonyl Coenzyme A,Not Available

# 3  
Old 08-13-2012
Thankyou for reply.

I checked but the ouptu is exactly same as input, there is no commas in place of column

I have a big file with many rows and columns and there is not even slight differnet in ouput and input

I tried this


Code:
 sed 's/ \{2,\}/,/g' saradrugbankgenedrugnewlist.txt >saradrugbankgenedrugnewlist2.txt

and output file is exactly same as input file
# 4  
Old 08-13-2012
try this.....

Code:
sed -e 's/[ \t]/,/'

# 5  
Old 08-13-2012
Hi

Thankyou

Now it's inserting comma only between first and second column and not between other columns

I tried this

Code:
bash-3.2$ sed -e 's/[ \t]/,/' saradrugbankgenedrugnewlist.txt >saradrugbankgenedrugnewlist2.txt

the outptut is like this where comma is onlt between first and second column not the the 2 anf 4th an so on

Code:
FHIT,Adenosine Monotungstate Not Available
    
CS ,Trifluoroacetonyl Coenzyme A Not Available

# 6  
Old 08-13-2012
try this.....

It will add comma for all the columns..
Code:
 sed 's/[\t]/,/g'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bring values in the second column into single line (comma sep) for uniq value in the first column

I want to bring values in the second column into single line for uniq value in the first column. My input jvm01, Web 2.0 Feature Pack Library jvm01, IBM WebSphere JAX-RS jvm01, Custom01 Shared Library jvm02, Web 2.0 Feature Pack Library jvm02, IBM WebSphere JAX-RS jvm03, Web 2.0 Feature... (10 Replies)
Discussion started by: kchinnam
10 Replies

2. Shell Programming and Scripting

Insert a new column with sequence number (Delimiter as comma)

Hi All, I have a file which has data like a,b c,d e,f g,h And I need to insert a new column at the begining with sequence no( 1 to n) 1,a,b 2,c,d 3,e,f 4,g,h Please let me know how to acheive this in unix (3 Replies)
Discussion started by: weknowd
3 Replies

3. Shell Programming and Scripting

Need to merge multiple text files vertically and place comma between fields

Hello expert friends, I'm writing a script to capture stats using sar and stuck up at report generation. I have around 10 files in a directory and need to merge them all vertically based on the time value of first column (output file should have only one time value) and insert comma after... (6 Replies)
Discussion started by: prvnrk
6 Replies

4. UNIX for Dummies Questions & Answers

insert comma

my file looks like this: 297 PC Closed 07/10/12 999000098 AMERICAN SOCIETY FOR HEALTHCAR 0.00 USD 1 NAI i want to look line this: 297,PC,Closed,07/10/12,999000098,AMERICAN SOCIETY FOR HEALTHCAR,0.00,USD,1,NAI (4 Replies)
Discussion started by: lawsongeek
4 Replies

5. Shell Programming and Scripting

Find regex, place on individual lines and insert blank line before

Hello, I have a file that I want to be able to insert a new line before every instance of a regex. I can get it to do this for each line that contains the regex, but not for each instance. Contents of infile: Test this 1... Test this 2... Test this 3... Test this 4... Test this... (2 Replies)
Discussion started by: deneuve01
2 Replies

6. Shell Programming and Scripting

Insert underscore in place of column

Hi I tried to put underscore in place of column in a big file with lots of oclumns using the programm sed 's//_/g' Its showing error bash-3.2$ sed 's//_/g'saradrugbankgenedrugnewlist.txt >saradrugbankgenedrugnewlist3.txt sed: -e expression #1, char 11: unknown option to `s' if... (24 Replies)
Discussion started by: manigrover
24 Replies

7. Shell Programming and Scripting

Insert a special character $ in place of extra spaces

Hi Experts, I have called some.txt with the following content. oracle HYRDSRVIHUB01 pts/0 TESTIHUB 07-JUN-10 CREATE TABLE TESTIHUB PHONE ... (12 Replies)
Discussion started by: naree
12 Replies

8. Shell Programming and Scripting

How to insert a string in a file at specified place?

Hi all, I want to insert a string in a specified place of a very large file. I am giving an example of the task: I love football. Above is a sentence in a file and I want to insert a string "the" between love and football. It is not sure that where this particular line exists. It has to... (4 Replies)
Discussion started by: naw_deepak
4 Replies

9. Shell Programming and Scripting

Place a comma on lines

Is it possible to place a comma in the desired places, like 10spaces after or 15 spaces after, irrespective of the contents??? Ex:File: TEST TEST: vimalthomaswants to place a comma can he do it in the desired places? as per the above file, i need to place a comma after 10th space... (4 Replies)
Discussion started by: vj8436
4 Replies

10. Shell Programming and Scripting

Insert comma based on max number of column

Hi, I am new to unix shell shell scripting. I have a specific requirement where I need to append comma's based on the max number of column in the file. Eg: If my source file look something like this, sengwa,china tom,america,northamerica smith,america walter My output file... (8 Replies)
Discussion started by: nicholas_ejn
8 Replies
Login or Register to Ask a Question