converting .txt to comma delimeted file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting converting .txt to comma delimeted file
# 1  
Old 09-16-2008
converting .txt to comma delimeted file

Dear all,

I have a file with 5L records. one of the record in the file is as shown below.
MARIA THOMAS
BASIL
1000 FM 1111 MD





GHANA
YY 77354 4774
99999999 1234567


I need to convert this record in below format

"","","","","MARIA","THOMAS","BASIL","","1000 FM 1111 MD","STE B","","","GHANA","YY","77354","4774",""1234567"99999999"
,"","","","","","","","","","","",""


Please suggest....Thanks in advance.
# 2  
Old 09-16-2008
Here is a start for you:

Code:
awk '
        { a[NR%11]=$0 }
        !NR%11 {
                # if NR%11 is 0, then we have a complete record, so print it
                # split the name into the b array
                split(a[1],b)
                print "\"\",\"\",\"\",\"\",\"" b[1] "\",\"" b[2] "\",\"" a[2]
        }
' inputfile

It only does the first few fields, but you should be able to figure out the rest from that.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk output is space delimeted not tab delimeted

In the below awk the output is space delimited, but it should be tab delimited. Did I not add the correct -F and OFS? Thank you :). The input file are rather large so I did not include them, but they are tab-delimeted files as well. awk awk -F'\t' -v OFS='\t' 'FNR==1 { next } > ... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Converting txt file into CSV using awk or sed

Hello folks I have a txt file of information about journal articles from different fields. I need to convert this information into a format that is easier for computers to manipulate for some research that I'm doing on how articles are cited. The file has some header information and then details... (8 Replies)
Discussion started by: ksk
8 Replies

3. Shell Programming and Scripting

Converting txt file to Excel file

Hi All, I have a text file with below content. TradeDate Name SecurityMnc ReasonDesc ======================================= 20120501 Robin ABC FO System Defect 20120502 Robin ABC FO System Defect I would want this in an excel file in 4 columns,... (3 Replies)
Discussion started by: robinbannis
3 Replies

4. Shell Programming and Scripting

Converting txt file in csv

HI All, I have a text file memory.txt which has following values. Average: 822387 7346605 89.93 288845 4176593 2044589 51883 2.47 7600 i want to convert this file in csv format and i am using following command to do it. sed s/_/\./g <... (3 Replies)
Discussion started by: mkashif
3 Replies

5. Shell Programming and Scripting

Converting comma separated to pipe delimited file

Hi, I came across a very good script to convert a comma seperated to pipe delimited file in this forum. the script serves most of the requirement but looks like it does not handle embedded double quotes and commas i.e if the input is like 1234, "value","first,second", "LDC5"monitor",... (15 Replies)
Discussion started by: anijan
15 Replies

6. UNIX for Dummies Questions & Answers

Converting txt file to csv file

Hi, Using rsync, I've sent the output to a text file. This is the text file : Pls help me on converting this text file to a csv file. Probably a script or sth to convert the text file to a csv file. (3 Replies)
Discussion started by: anaigini45
3 Replies

7. Shell Programming and Scripting

converting xls file to txt file and xls to csv

I need to convert an excel file into a text file and an excel file into a CSV file.. any code to do that is appreciated thanks (6 Replies)
Discussion started by: bandar007
6 Replies

8. UNIX for Advanced & Expert Users

converting a .txt file to comma delimeted file

Dear all, I have a file with 5L records. one of the record in the file is as shown below. MARIA THOMAS BASIL 1000 FM 1111 MD ... (1 Reply)
Discussion started by: OSD
1 Replies

9. Shell Programming and Scripting

Converting Tab delimited file to Comma delimited file in Unix

Hi, Can anyone let me know on how to convert a Tab delimited file to Comma delimited file in Unix Thanks!! (22 Replies)
Discussion started by: charan81
22 Replies

10. UNIX for Dummies Questions & Answers

converting .txt

Hello, I transferred some .txt files from windows to Unix. When i used the editor in Unix to open up the file, all the <cr> show up. How to I get rid of all of them? (4 Replies)
Discussion started by: laila63
4 Replies
Login or Register to Ask a Question