2 added 6 characters in body
source | link

I have a table

+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| foo   | varchar(10) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+

I'd like to define two scripts, one that can transform such table into csv and one that can transform it back.

I know that that kind of possbile with sed

sed -e '1d;3d;$d' -e 's/^|//' -e 's/|$//' -e 's/|/,/g' file

sed -e '1d;3d;$d' -e 's/^|//' -e 's/|$//' -e 's/|/,/g' file

But this would be unreliable. 
Reliable way would be to find positions of | character on the second line (except first and last) and on each line turn characters in this positions to , and remove whitespace around them. It can probably done with awk, but I don't know how.

I have a table

+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| foo   | varchar(10) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+

I'd like to define two scripts, one that can transform such table into csv and one that can transform it back.

I know that that kind of possbile with sed

sed -e '1d;3d;$d' -e 's/^|//' -e 's/|$//' -e 's/|/,/g' file

But this would be unreliable. Reliable way would be to find positions of | character on the second line (except first and last) and on each line turn characters in this positions to , and remove whitespace around them. It can probably done with awk, but I don't know how.

I have a table

+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| foo   | varchar(10) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+

I'd like to define two scripts, one that can transform such table into csv and one that can transform it back.

I know that that kind of possbile with sed

sed -e '1d;3d;$d' -e 's/^|//' -e 's/|$//' -e 's/|/,/g' file

But this would be unreliable. 
Reliable way would be to find positions of | character on the second line (except first and last) and on each line turn characters in this positions to , and remove whitespace around them. It can probably done with awk, but I don't know how.

1
source | link

Transform table into csv and back

I have a table

+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | NO   | PRI | NULL    |       |
| foo   | varchar(10) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+

I'd like to define two scripts, one that can transform such table into csv and one that can transform it back.

I know that that kind of possbile with sed

sed -e '1d;3d;$d' -e 's/^|//' -e 's/|$//' -e 's/|/,/g' file

But this would be unreliable. Reliable way would be to find positions of | character on the second line (except first and last) and on each line turn characters in this positions to , and remove whitespace around them. It can probably done with awk, but I don't know how.