Simple shell sorting and statistics.

Source: Internet
Author: User
Tags call shell

During the bug quality analysis, the word segmentation should be sorted and de-duplicated, so we thought of sort and uniq.

It is very convenient to call shell through python.

#-*-Coding: UTF-8 -*-
Import OS
Import sys

Def cws_statistics (flag, afile, bfile ):
If not OS. Path. isfile (afile ):
Print "wordlist dose't exist! "
Else:
If flag = "0 ":
OS. system ("sort-F" + afile + "| uniq-c | sort-K 1-n-r | awk 'function trim (STR) {sub (/^ [] */, \ "\", STR); Return STR} {print trim ($0)} '> "+ bfile)
Elif flag = "1 ":
OS. system ("sort" + afile + "| uniq-c | sort-K 1-n-r | awk 'function trim (STR) {sub (/^ [] */, \ "\", STR); Return STR} {print trim ($0)} '| awk-f'' {If (length ($2 )! = 1) Print $0} '> "+ bfile)
Pass
Print "cws_statistics is OK! % S => % s "% (afile, bfile)


If _ name _ = "_ main __":
If Len (SYS. argv) = 4:
# Print sys. argv
Cws_statistics (SYS. argv [1], SYS. argv [2], SYS. argv [3])
Else:
Print "Usage: Python cws_statistics.py [flag] [wordlist] [resultfile]"
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.