.idt file to csv file


 
Thread Tools Search this Thread
Top Forums Programming .idt file to csv file
# 1  
Old 03-29-2012
.idt file to csv file

hi frnds
can somebody help me how to convert data from unix file to csv using c++ e.g

I have input called file.idt

Code:
COMPANY = MYCOMPONY
SECTORTYPE = SECTORA
ADDRESS = MY HOME
BILL = MONTHLY
END
USERNAME = MIKE
 SECTORTYPE= SECTORB
OPTION = USER
DATA = RAW
LOGIN = DECEMBER
END

i want to generate 2 files in csv

SECTORA.csv

Code:
company,sectortype,address,bill,
'mycomapany,'sectorc,'myhome,'monthly,


SECTORB.csv

Code:
username,sectortype,option,data,login,
'mike,'sectorc,'user,'raw,'december,

Moderator's Comments:
Mod Comment Please use code tags for code and output.

Last edited by Corona688; 03-30-2012 at 01:56 PM..
# 2  
Old 03-30-2012
Where are you getting 'sectorc'? That is not in your input file.
# 3  
Old 03-30-2012
Code:
$ cat csv.awk

BEGIN { FS=" *= *"
        L=split("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z",FNAMES," ");
 }

function print_company()
{
        # Generate filename.
        # goes A, B, C, D, ... Z, AA, AB, AC, ..., AZ, BA, ...
        F=FILE++;       FILENAME="";
        do {
                FILENAME=FILENAME FNAMES[(F%L)+1];
                F=sprintf("%d", F/26);
        } while(F>26)
        FILENAME="SECTOR" FILENAME ".csv"

        if(A["COMPANY"])
        {
                print "company,sectortype,address,bill," >FILENAME;
                printf("'%s,'%s,'%s,'%s,\n",
                        A["COMPANY"], A["SECTORTYPE"],
                        A["ADDRESS"], A["BILL"]) >FILENAME;
        }
        else if(A["USERNAME"])
        {
                print "username,sectortype,option,data,login," >FILENAME;
                printf("'%s,'%s,'%s,'%s,'%s,\n",
                        A["USERNAME"], A["SECTORTYPE"],
                        A["OPTION"], A["DATA"], A["LOGIN"])>FILENAME;
        }

        for(X in A) delete A[X];
}

{ sub(/^ */, ""); }

NF>1 {  A[$1]=$2 }

$1 == "END" {   print_company();        }
END {           print_company();        }

$ awk -f csv.awk data
$ tail SECTORA.csv SECTORB.csv
==> SECTORA.csv <==
company,sectortype,address,bill,
'MYCOMPONY,'SECTORA,'MY HOME,'MONTHLY,

==> SECTORB.csv <==
username,sectortype,option,data,login,
'MIKE,'SECTORB,'USER,'RAW,'DECEMBER,

$

Use gawk or nawk if awk doesn't work.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare every column from one csv file to another csv file

1.csv contains following column- Empid code loc port 101 A xy 01 102 B zx 78 103 A cg 12 104 G xy 78 2.csv contains follwing data- Empid code loc port 101 A gf 01 102 B zx 78 103 C cg 32 104 ... (1 Reply)
Discussion started by: rishabh
1 Replies

2. Shell Programming and Scripting

Save output of updated csv file as csv file itself, part 2

Hi, I have another problem. I want to sort another csv file by the first field. result.csv SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw /home/intannf/foto5/2015_0313_090651_219.JPG,0.,-7.77223,110.37310,30.75,996.46,148.75,180.94,182.00,63.92 ... (2 Replies)
Discussion started by: refrain
2 Replies

3. Shell Programming and Scripting

Save output of updated csv file as csv file itself

Hi, all I want to sort a csv file based on timestamp from oldest to newest and save the output as csv file itself. Here is an example of my csv file. test.csv SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0739.JPG,2015:02:17 11:32:21 /home/intannf/foto/IMG_0749.JPG,2015:02:17 11:37:28... (10 Replies)
Discussion started by: refrain
10 Replies

4. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

5. Shell Programming and Scripting

Match columns from two csv files and update field in one of the csv file

Hi, I have a file of csv data, which looks like this: file1: 1AA,LGV_PONCEY_LES_ATHEE,1,\N,1,00020460E1,0,\N,\N,\N,\N,2,00.22335321,0.00466628 2BB,LES_POUGES_ASF,\N,200,200,00006298G1,0,\N,\N,\N,\N,1,00.30887539,0.00050312... (10 Replies)
Discussion started by: djoseph
10 Replies

6. Shell Programming and Scripting

How to convert excel file to csv file or text file?

Hi all, I need to find a way to convert excel file into csv or a text file in linux command. The reason is I have hundreds of files to convert. Another complication is the I need to delete the first 5 lines of the excel file before conversion. so for instance input.xls description of... (6 Replies)
Discussion started by: johnkim0806
6 Replies

7. Shell Programming and Scripting

Compare 2 csv files in ksh and o/p the difference in a new csv file

(say) I have 2 csv files - file1.csv & file2.csv as mentioned below: file1.csv ID,version,cost 1000,1,30 2000,2,40 3000,3,50 4000,4,60 file2.csv ID,version,cost 1000,1,30 2000,2,45 3000,4,55 6000,5,70 The... (7 Replies)
Discussion started by: Naresh101
7 Replies

8. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

9. Shell Programming and Scripting

Need to compare two csv files values and write into another csv file

Hi all, Am new to scripting. So i just need your ideas to help me out. Here goes my requirement. I have two csv files 1.csv 2.csv abc,1.24 abc,1 def,2.13 def,1 I need to compare the first column of 1.csv with 2.csv and if matches then need to compare... (2 Replies)
Discussion started by: chinnahyd
2 Replies
Login or Register to Ask a Question