Shell script Test

Source: Internet
Author: User

The AAA. Log content of the file to be processed:

09/26 00:00:08 116.41834259033203 39.90071597768346 116.60888671875 35.38904996691167
09/26 00:01:34 121.13089397549632 30.98941357306606 121.55966117978099 31.149880293437714
09/26 00:01:51 117.12383329868318 39.243494180634734 117.12383329868318 39.243494180634734 0
09/26 00:03:55 117.12383329868318 39.243494180634734 117.12383329868318 39.243494180634734 0
09/26 00:04:07 106.70314550399783 26.556866721950268 106.72096878290178 26.58711559252519
09/26 00:05:23 117.12383329868318 39.243494180634734 117.12383329868318 39.243494180634734 0
09/26 00:05:38 114.18694585561754 36.686433818538205 115.66599234938623 37.7350984521996
09/26 00:05:57 121.13089397549632 30.98941357306606 121.55966117978099 31.149880293437714

Handling requirements:

The last column is less than lines, and the content of the third to sixth columns is saved to another file, bbb.txt.

Shell script program:

#! /Bin/bash
Echo ''> bbb.txt
While read line # Read the file "/bak/log/aaalog" line by line"
Do
Distance = $ (echo "$ line" | awk-F' \ t'' {print $7} ') # retrieves the seventh column of each row and assigns the value to distance. Syntax: temp = $ (Value assignment content) or temp = 'value assignment content'. Note that it is not a single or double quotation mark.

# If [[$ distance <3000]; then
# Echo "$ line" | awk-F' \ t'' {print $3, $4, $5, $6} '> bbb.txt
# Fi
[$ Distance <50000] & Echo "$ line" | awk-F' \ t' {print $3, $4, $5, $6} '> bbb.txt extract the seven rows smaller than and specify the output columns to the bbb.txt file.
Done </bak/log/aaalog

# Note:

# Condition comparison Syntax: If [comparison condition]; then... Fi

# Or: [comparison conditions] & what to do.

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.