How to extract data from html table in shell script?

前端 未结 6 1452
[愿得一人]
[愿得一人] 2020-11-30 11:42

I am trying to create a BASH script what would extract the data from HTML table. Below is the example of table from where I need to extract data:

6条回答
  •  [愿得一人]
    2020-11-30 12:12

    You can parse the file using Ex editor (part of Vim) by removing HTML tags, e.g.:

    $ ex -s +'%s/<[^>]\+>/ /g' +'v/0/d' +'wq! /dev/stdout' table.html 
      SAVE_DOCUMENT  OK  0.406 s  
      GET_DOCUMENT  OK  0.332 s  
      DVK_SEND  OK  0.001 s  
      DVK_RECEIVE  OK  0.001 s  
      GET_USER_INFO  OK  0.143 s  
      NOTIFICATIONS  OK  0.001 s  
      ERROR_LOG  OK  0.001 s  
      SUMMARY_STATUS  OK  0.888 s 
    

    Here is shorter version by printing the whole file without HTML tags:

    $ ex +'%s/<[^>]\+>/ /g|%p' -scq! table.html
    

    Explanation:

    • %s/<[^>]\+>/ /g - Substitute all HTML tags into empty space.
    • v/0/d - Deletes all lines without 0.
    • wq! /dev/stdout - Quits editor and writes the buffer to the standard output.

提交回复
热议问题