Processing string list
Process string list. Use a regular expression to search in a string list.
Find the first matched element:
> (set 'l '("WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated. Please use org.apache.hadoop.log.metrics.EventCounter in all the \log4j.properties files." "recommend" "search" "test"))("WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated. Please use org.apache.hadoop.log.metrics.EventCounter in all the log4j.prope\rties files." "recommend" "search" "test")> (find "WARN" l 1)0> (find "WARN3" l 1)
Note that the third parameter is used to indicate that the regular expression is used for search. 1 indicates that the case is not sensitive, and 0 indicates that the request is sensitive.
Use a regular expression to search for and delete the string in the string list
(context 'STRING_LIST);; @param case-insensitive 1 for case-insensitive search or 0 for no special options(define (remove str-list str-regex case-insensitive) (do-while i (begin (set 'i (find str-regex str-list case-insensitive)) (if i (pop str-list i)))) str-list )
In this way, the following function uses the above function to filter out the string list returned by the hive command, leaving only the database name.
;; @syntax (HIVE:show-dbs) (define (show-dbs) (set 'r (exec (format "hive -e 'show databases' 2>&1"))) (set 'r (STRING_LIST:remove r "^WARNING.+" 1)) (set 'r (STRING_LIST:remove r "^Logging.+" 1)) (set 'r (STRING_LIST:remove r "^Hive.+" 1)) (set 'r (STRING_LIST:remove r "OK" 1)) (STRING_LIST:remove r "^Time taken.+" 1) )