O
O
oleww052019-01-30 23:57:19
bash
oleww05, 2019-01-30 23:57:19

How to output in one line?

There is a table:

<table class="searchDetails">
          <tr>
            <th>Автор:
            </th>
            <td><span class="hl_none">Ф. И. О.</span>
            </td>
          </tr>
          <tr>
            <th>Сведения:
            </th>
            <td><span class="hl_none">ППП., 2011</span>
            </td>
          </tr>
          <tr>
            <th>Тематика:
            </th>
            <td><span class="hl_none">ООО</span>
            </td>
          </tr>
      </table>
        <div class="searchLink"></div>
И Т.Д.

It is necessary to display the contents of "searchDetails" in one line, for example:
Author: Full name
. document: DOC
etc.
I use this script:
#!/bin/bash
A=$(cat table.htm | sed -n -e '/<table class=\"searchDetails\">/,/<div class=\"searchLink\">/ p' | grep "<span class=\"hl_none\">" -B 2 | grep "<th>" | sed -e 's/<th>//' -e 's/            //' | tr -d '\r')
A2=$(cat table.htm | sed -n -e '/<table class=\"searchDetails\">/,/<div class=\"searchLink\">/ p' | grep "<span class=\"hl_none\">" | sed -e 's/.*<span class=\"hl_none\">//' -e 's/<\/span>//' | tr -d '\r')
B=$(paste -d " " <(echo "$A") <(echo "$A2"))
echo "$B"

As a result, this is the result, but it does not fit:
Author: Full name
Information: PPP., 2011
Subject: LLC
Author: Full name
Organization: LLC "ZAO"
Information: PPP., 2011
Document type: DOC
ETC.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitsliputsli, 2019-01-31
@oleww05

With sed like this:

sed -n '/<th>\|<td>\|<\/table/p' t.html | sed 's/^\s*//' | sed ':a; N; s/\n/ /; ta;' | sed 's/ <\/table> /\n/;s/<[^>]*>//g'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question