3

How can I insert a horizontal line (hline) in a bash/sh source code block? My goal is to separate the header line from the rest.

#+begin_src sh
echo "header1,header2"
echo "???"  # placeholder for the magic value
echo "value1,value2"
echo "value1,value2"
#+end_src

The desired outcome would be

#+RESULTS:
| header1 | header2 |
|---------+---------|
| value1  | value2  |
| value1  | value2  |

In a Python src block I can insert a None-Value and get an hline. I hope there is a possibility.

Edit: @jagrg answers solves the problem to separate the header from the rest I would also to insert a hline at any point in the table. Here is the expected outcome.

#+begin_src bash :colnames '("header1" "header2")
echo "value1,value2"
echo "value1,value2"
echo "???" # magic value
echo "value1,value2"
#+end_src

#+RESULTS:
| header1 | header2 |
|---------+---------|
| value1  | value2  |
| value1  | value2  |
|---------+---------|
| value1  | value2  |

I tried echo hline and echo "hline" with no success. I also looked in the code of ob-shell.el and it looks that a simple echo hline should do it but it doesn't.

3

You can specify column names as header arguments (see here).

#+begin_src sh :colnames '("header1" "header2")
echo "value1,value2"
echo "value1,value2"
#+end_src

#+RESULTS:
| header1 | header2 |
|---------+---------|
| value1  | value2  |
| value1  | value2  |

To answer your second question, here's a solution you can try using sed (see this thread).

#+begin_src sh :results raw
(
echo "header,header2"
echo ","
echo "value1,value2"
echo "value1,value2"
echo ","
echo "value1,value2"
) | sed -re 's/^|,/|/g' -e 's/^\|$/|-/'
#+end_src

#+RESULTS:
| header | header2 |
|--------+---------|
| value1 | value2  |
| value1 | value2  |
|--------+---------|
| value1 | value2  |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.