TEXT Files to CSV

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • praveenholal
    New Member
    • Feb 2007
    • 19

    TEXT Files to CSV

    Hi Freinds ,

    I want to convert the files that are in text format (.txt) to CSV file. I am working on Linux. So can anyone guide me.

    Here is my problem Description
    I have some result files which contains text fields and numeric fields which are seperated by tab and also there is a - between two numbers 10-20 .

    Another thing is that colons are also present in between in files
    name :: praveen

    Also my another concern is if have different kinds of output fields in the file how to convert those into csv. what i mean is , for example if there is a text file in which i will have the following fields

    Name Age Location School College

    So in the result files all the above columns may be present or any of these may be present . But minimum first 3 columns will be present . So what is the solution . Does the csv file contain a blank if the values are not specified ?


    Then how should i convert these kind of text files into csv file (Comma Seperated values) Files .

    Should i write my own code or is there any utilities that can help me convert these text files into csv files

    Thanks in advance
    Praveen
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    I think a Linux tool such as awk or sed might be of more use to you in this case - you can use those to replace the tabs with the commas (or is it not currently in the format you want?).

    What is the format of the current file, specifically? (Can you post two lines from it so we can get an idea?)

    Comment

    • DeMan
      Top Contributor
      • Nov 2006
      • 1799

      #3
      A csv file is a file with entries delimited by a comma (which can be opened in excel among other things).

      Assuming you want every tab space in the text file to be a "breaker" between columns, then it is a matter of replacing the blank with a comma. Assuming you want to split the hyphenated numbers, then you also replace the hphen with a comma (otherwise you can treat it as text).

      a blank cell will be recognised if you add two commas (that is, if you need to pad out to 3 columns, just add commas until it pads far enough).

      Comment

      • praveenholal
        New Member
        • Feb 2007
        • 19

        #4
        Originally posted by sicarie
        I think a Linux tool such as awk or sed might be of more use to you in this case - you can use those to replace the tabs with the commas (or is it not currently in the format you want?).

        What is the format of the current file, specifically? (Can you post two lines from it so we can get an idea?)
        Thank you for your reply. I solved the problem by writing some programs .

        Comment

        • praveenholal
          New Member
          • Feb 2007
          • 19

          #5
          Thank you DeManfor the response and reply.

          I wanted some clarifications regarding csv from you all

          1) Should we include the column header in csv for example consider the below data

          Age Location
          25 California
          26 London
          27 Rome
          28 Amsterdam

          In my csv file should the header Age,Location be placed or only the data should be there .


          For example which of the below is the correct format of csv file

          Below Data is with Header (Age,Location)
          Age, Location
          25,California
          26,London
          27,Rome
          28,Amsterdam


          Now the data below this line doesn contain header , only pure data
          25,California
          26,London
          27,Rome
          28,Amsterdam


          So which one of the above is in correct csv format


          2)Whether each line in the csv file should end with a new line character or the data should be written into csv file continously
          for example :

          25,California,2 6,London,27,Rom e,28,Amsterdam


          So i will be very thankful to u all if you clarify my these doubts

          Comment

          • DeMan
            Top Contributor
            • Nov 2006
            • 1799

            #6
            If the header is important then include it in the csv (as you might have noticed though, the formatting/underlining etc is ignored)

            Comment

            Working...