sort

Hadoop兮,杀鸡别用牛刀,python+shell实现一般日志文件的查询、统计

拜拜、爱过 提交于 2019-12-05 14:23:49
简单的日志统计是不需要使用重量级的Hadoop,我用python实现了日志的统计。原理是用fabric登录到远程linux,组合使用grep、uniq、sort、awk对日志进行操作,可以根据正则表达式指定规则抽取符合规则的日志,做查询,计数,分类统计。 注意:要安装 fabric 库 主文件:LogQuery.py #encoding=utf-8 from fabric.api import run,env,local,cd from fabric.tasks import execute,abort from fabric.contrib.console import confirm import logging logging.basicConfig(format='[%(levelname)s]: %(message)s', level=logging.DEBUG) logger = logging.getLogger(__name__) logging.getLogger('paramiko.transport').setLevel(logging.ERROR) logger.setLevel(logging.DEBUG) EXECUTE_RESULT = {} def hosts(hostarr): ''' set hosts hostarr:[(hostname

10-排序6 Sort with Swap(0, i) (25 分)

♀尐吖头ヾ 提交于 2019-12-05 12:18:59
Given any permutation of the numbers {0, 1, 2,..., N − 1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may apply the swap operations in the following way: Swap(0, 1) => {4, 1, 2, 0, 3} Swap(0, 3) => {4, 1, 2, 3, 0} Swap(0, 4) => {0, 1, 2, 3, 4} Now you are asked to find the minimum number of swaps need to sort the given permutation of the first N nonnegative integers. Input Specification: Each input file contains one test case, which gives a positive N ( ≤ 1 0 ​^5 ​​) followed by a

MySQL入门笔记1

☆樱花仙子☆ 提交于 2019-12-05 11:34:51
SQL语句基本用法: 1. SQL语句分类: 1.1 数据定义语言 : 简称DDL(Data Definition Language),用来定义数据库对象:数据库,表,列等。关键字:create,alter(修 改),drop(删除)等 ; 1.2 数据操作语言:(重点掌握) 简称DML(Data Manipulation Language),用来对数据库中表的记录进行更新。关键字:insert,delete,update 等; 1.3 数据控制语言: 简称DCL(Data Control Language),用来定义数据库的访问权限和安全级别,及创建用户; 1.4 数据查询语言:(重点掌握) 简称DQL(Data Query Language),用来查询数据库中表的记录。关键字:select,from,where等。 2.SQL通用语法: 2.1 语法格式: (1)SQL语句可以单行或多行书写,需以英文分号结尾; (2) 可使用空格、缩进、折行来增强语句的可读性(由于SQL语句只以分号作为结尾,所以原则上可以无限制空格 折行); (3)MySQL数据库的SQL语句不区分大小写,关键字建议使用大写,变量名使用小写,例如:SELECT * FROM user。 (4)SQL通用注释: 单行注释:--空格+注释内容 多行注释:/* 注释内容*/ (注:多行注释不能嵌套)

shell 编程求交集,并集,补集

随声附和 提交于 2019-12-05 08:51:13
1.方法一 grep -f (求两个文件的交集,不要有效) 文件a cat a 12 34 13 25 文件b cat b 13 35 78 14 (1).交集 grep -f a b 13 (2).补集 a-b grep -v -f b a 12 34 25 b-a grep -v -f b a (3).并集 2.方法二 sort (1).交集 sort a b|uniq -d 并集 sort a b|uniq 补集 a-b sort a b b|uniq -u 来源: https://www.cnblogs.com/sun5/p/11917371.html

Collections工具类中的sort方法如何比较元素?

亡梦爱人 提交于 2019-12-05 08:38:23
Collections 工具类的 sort() 方法有两种方式 第一种要求传入的待排序容器中存放的对象比较实现 Comparable 接口以实现元素的比较 第二种不强制性的要求容器中的元素必须可比较,但要求传入参数 Comparator 接口的子类,需要重写 compare() 方法实现元素的比较规则,其实就是通过接口注入比较元素大小的算法,这就是回调模式的应用 Java 自学指南 Java 面试题汇总PC端浏览【点这里】 Java知识图谱 Java 面试题汇总小程序浏览,扫二维码 所有资源 资源汇总于公众号 来源: https://www.cnblogs.com/ConstXiong/p/11915625.html

hive 中 Order by, Sort by ,Dristribute by,Cluster By 的作用和用法

∥☆過路亽.° 提交于 2019-12-05 06:49:30
order by order by 会对输入做全局排序,因此只有一个reducer(多个reducer无法保证全局有序) 只有一个reducer,会导致当输入规模较大时,需要较长的计算时间。 set hive.mapred.mode=nonstrict; (default value / 默认值) set hive.mapred.mode=strict; order by 和数据库中的Order by 功能一致,按照某一项 & 几项 排序输出。 与数据库中 order by 的区别在于在hive.mapred.mode = strict 模式下 必须指定 limit 否则执行会报错。 hive> select * from test order by id; FAILED: Error in semantic analysis: 1:28 In strict mode, if ORDER BY is specified, LIMIT must also be specified. Error encountered near token ‘id’ 原因: 在order by 状态下所有数据会到一台服务器进行reduce操作也即只有一个reduce,如果在数据量大的情况下会出现无法输出结果的情况,如果进行 limit n ,那只有 n * map number 条记录而已

经典排序算法总结

喜欢而已 提交于 2019-12-05 04:26:58
概述 选泡插, 快归堆希桶计基, n方n老(log)n一三, 对n加kn乘k, 不稳稳稳不稳稳, 不稳不稳稳稳稳。 排序算法 平均时间复杂度 最好情况 最坏情况 空间复杂度 排序方式 稳定性 冒泡排序(BubbleSort) O(n 2 ) O(n) O(n 2 ) O(1) In-place 稳定 选择排序(SelectSort) O(n 2 ) O(n 2 ) O(n 2 ) O(1) In-place 不稳 插入排序(InsertSort) O(n 2 ) O(n) O(n 2 ) O(1) In-place 稳定 希尔排序(ShellSort) O(n 1.3 ) O(n) O(n log 2 n) O(1) In-place 不稳 归并排序(MergeSort) O(n log n) O(n log n) O(n log n) O(n) Out-place 稳定 快速排序(QuickSort) O(n log n) O(n log n) O(n 2 ) O(log n) In-place 不稳 堆排序(HeapSort) O(n log n) O(n log n) O(n log n) O(1) In-place 不稳 计数排序(CountSort) O(n + k) O(n + k) O(n + k) O(k) Out-place 稳定 桶排序(BucketSort)

Python中 字典排序、列表排序

强颜欢笑 提交于 2019-12-05 02:28:42
一、字典排序 在程序中使用字典进行数据信息统计时,由于字典是无序的所以打印字典时内容也是无序的。因此,为了使统计得到的结果更方便查看需要进行排序。Python中字典的排序分为按“键”排序和按“值”排序。 1、按“值”排序 按“值”排序就是根据字典的值进行排序,可以使用内置的sorted()函数。 sorted(iterable[, cmp[, key[, reverse]]]) (1)iterable:是可迭代类型类型; (2)cmp:用于比较的函数,比较什么由key决定,有默认值,迭代集合中的一项; (3)key:用列表元素的某个属性和函数进行作为关键字,有默认值,迭代集合中的一项; (4)reverse:排序规则. reverse = True 或者 reverse = False,有默认值,默认为升序排列(False)。 返回值: 是一个经过排序的可迭代类型 ,与iterable一样。一般来说,cmp和key可以使用lambda表达式。 如果对字典进行排序,常用的形式如下: sorted(dict.items(), key=lambda e:e[1], reverse=True) , 其中e表示dict.items()中的一个元素,e[1]则表示按 值排序如果把e[1]改成e[0],那么则是按键排序,reverse=False可以省略,默认为升序排列。 说明:字典的items

golang sort 排序

对着背影说爱祢 提交于 2019-12-05 01:50:23
func Float64s(a []float64) // Float64s 以升序排序 float64 切片 func Float64sAreSorted(a []float64) bool // Float64sAreSorted 判定 float64 切片是否已经进行排序 func Ints(a []int) // Ints 以升序排列 int 切片。 func IntsAreSorted(a []int) bool // IntsAreSorted 判断 int 切片是否已经按升序排列。 func IsSorted(data Interface) bool // IsSorted 判断数据是否已经排序。包括各种可sort的数据类型的判断. func Strings(a []string) // Strings 以升序排列 string 切片。 func StringsAreSorted(a []string) bool // StringsAreSorted 判断 string 切片是否已经按升序排列。 package main import ( "fmt" "sort" ) func main() { a := []int{1, 3, 5, 4, 2} b := []float64{1.1, 2.3, 5.3, 3.4} c := []string{"ds", "ca",

golang标准库-排序(sort)

℡╲_俬逩灬. 提交于 2019-12-05 01:50:07
sort包,顾名思义用来排序的包,里面提供的工具方法可以对int,string,float64类型的切片进行快速排序和查找,如果自己定义的数据类型,实现了sort.Interface类型接口,也可以进行排序和查找。这个包方法不算多,也不复杂。本文讲解了sort包90%的内容 先看三个类型的基本排序方法: func Ints(a [] int ) // 将a排序为递增顺序。 func Float64s(a [] float64 ) // 将a排序为递增顺序。 func Strings(a [] string ) // 将a排序为递增顺序。 下面看例子,分别对int,float64,string类型的切片进行排序: func main() { // 对int切片快速排序 i := []int{3,2,1,12,32,5,3} sort.Ints(i) fmt.Println(i) // 结果:[1 2 3 3 5 12 32] // 对float64切片快速排序 f := []float64{0.6,9.4,0.4,1.2,3.1} sort.Float64s(f) fmt.Println(f) // 结果:[0.4 0.6 1.2 3.1 9.4] // 对string切片快速排序 s := []string{"a","A","AA","aa","Aa","aA","AAA",