Processing string list

Source: Internet
Author: User

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)  )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.