How Do I Replace New Line And Space In ?
I need to create calendar in table (html) use replace space and new line in bash script. I use this code: cal | sed -e 's/ / /g' >>Solution 1:
With GNU sed and BSD cal:
LC_ALL=en_US.UTF-8 cal -h | sed '1{s|^|<html><table>\n<tr><thcolspan="7">|;s|$|</th></tr>|};2,${s|\(..\) |<td>\1</td>|g;s|^|<tr>|;s|$|</tr>|};$s|$|\n</table></html>|'
-h
: Turns off highlighting of today
Output:
<html><table><tr><thcolspan="7"> January 2018 </th></tr><tr><td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td></tr><tr><td></td><td> 1</td><td> 2</td><td> 3</td><td> 4</td><td> 5</td><td> 6</td></tr><tr><td> 7</td><td> 8</td><td> 9</td><td>10</td><td>11</td><td>12</td><td>13</td></tr><tr><td>14</td><td>15</td><td>16</td><td>17</td><td>18</td><td>19</td><td>20</td></tr><tr><td>21</td><td>22</td><td>23</td><td>24</td><td>25</td><td>26</td><td>27</td></tr><tr><td>28</td><td>29</td><td>30</td><td>31</td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></table></html>
I need to create calendar in table (html) use replace space and new line in bash script. I use this code: cal | sed -e 's/ / /g' >>
Solution 1:
With GNU sed and BSD cal:
LC_ALL=en_US.UTF-8 cal -h | sed '1{s|^|<html><table>\n<tr><thcolspan="7">|;s|$|</th></tr>|};2,${s|\(..\) |<td>\1</td>|g;s|^|<tr>|;s|$|</tr>|};$s|$|\n</table></html>|'
-h
: Turns off highlighting of today
Output:
<html><table><tr><thcolspan="7"> January 2018 </th></tr><tr><td>Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td></tr><tr><td></td><td> 1</td><td> 2</td><td> 3</td><td> 4</td><td> 5</td><td> 6</td></tr><tr><td> 7</td><td> 8</td><td> 9</td><td>10</td><td>11</td><td>12</td><td>13</td></tr><tr><td>14</td><td>15</td><td>16</td><td>17</td><td>18</td><td>19</td><td>20</td></tr><tr><td>21</td><td>22</td><td>23</td><td>24</td><td>25</td><td>26</td><td>27</td></tr><tr><td>28</td><td>29</td><td>30</td><td>31</td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></table></html>
Post a Comment for "How Do I Replace New Line And Space In ?"