Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How could I format this so it fits a csv format? I accidentally deleted my table and now I need to export this data.

+-----+---------------------------------+-------------+-------------------+
| id  | email                           | firstName   | lastName          |
+-----+---------------------------------+-------------+-------------------+
|   6 | email@email.com                 | Person1     | Person1           |
|   7 | email2@email.com                | Person2     | Person2           |
|   8 | email3@email.com                | Person3     | Person3           |
+-----+---------------------------------+-------------+-------------------+

This is a text file I made before, so how could I remove the lines so that it goes like:

"6","email@email.com","Person1","Person1"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
145 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can do it manually in Excel (open file, Data -> Text to Columns, Fixed width.

Regex-wise, 2 options:

  • replace stuff:

    s/^|s+/"/;
    s/s+|s+/","/g;
    s/s*|$/"/;
    
  • match stuff:

    s/^|s+(d+)s+|s+(S+)s+|s+(S+)s+|s+(S+)s+|$/"$1","$2","$3,"$4"/
    

Of course, the exact syntax depends on the language you use.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...