Shell gets two columns of values from a single line of files

Source: Internet
Author: User
  • The contents of the log file are as follows:
    logid=2210608107 worker_id=140610281404160 optime=1452598610.631276 msg=service+not+found+in+share+memory service=Redis_doc_push
  • The post-column output is obtained through awk, and the disadvantage is that if the log is printed in a format that does not have spaces, you cannot use the
    cat xxx.log | grep -oP "logid=\d+.*service=\w+" | awk -F‘ ‘ ‘{print $1,$NF}‘
  • Capturing a group with a regular expression, replacing the entire row with a value of two groups with SED
    cat xxx.log | sed -r "s/.*?logid=([0-9]+).*?service=(\w+).*?/\1,\2/"
  • Shell gets two columns of values from a single line of files

    Related Article

    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.