cat

Linux Shell 文本处理工具集锦

百般思念 提交于 2019-11-28 23:57:12
本文将介绍Linux下使用Shell处理文本时最常用的工具: find、grep、xargs、sort、uniq、tr、cut、paste、wc、sed、awk; 提供的例子和参数都是最常用和最为实用的; 我对shell脚本使用的原则是命令单行书写,尽量不要超过2行; 如果有更为复杂的任务需求,还是考虑python吧; find 文件查找 查找txt和pdf文件 find . \( -name "*.txt" -o -name "*.pdf" \) -print 正则方式查找.txt和pdf find . -regex ".*\(\.txt|\.pdf\)$" -iregex: 忽略大小写的正则 否定参数 查找所有非txt文本 find . ! -name "*.txt" -print 指定搜索深度 打印出当前目录的文件(深度为1) find . -maxdepth 1 -type f 定制搜索 按类型搜索: find . -type d -print //只列出所有目录 -type f 文件 / l 符号链接 按时间搜索: -atime 访问时间 (单位是天,分钟单位则是-amin,以下类似) -mtime 修改时间 (内容被修改) -ctime 变化时间 (元数据或权限变化) 最近7天被访问过的所有文件: find . -atime 7 -type f -print 按大小搜索

型变(逆变)函数

白昼怎懂夜的黑 提交于 2019-11-28 22:15:08
另一个可以帮助理解型变的例子是 Scala 标准库中的 trait Function1[-T, +R] 。 Function1 表示具有一个参数的函数,其中第一个类型参数 T 表示参数类型,第二个类型参数 R 表示返回类型。 Function1 在其参数类型上是逆变的,并且在其返回类型上是协变的。 对于这个例子,我们将使用文字符号 A => B 来表示 Function1[A, B] 。 假设前面使用过的类似 Cat , Dog , Animal 的继承关系,加上以下内容: abstract class SmallAnimal extends Animal case class Mouse(name: String) extends SmallAnimal 假设我们正在处理接受动物类型的函数,并返回他们的食物类型。 如果我们想要一个 Cat => SmallAnimal (因为猫吃小动物),但是给它一个 Animal => Mouse ,我们的程序仍然可以工作。 直观地看,一个 Animal => Mouse 的函数仍然会接受一个 Cat 作为参数,因为 Cat 即是一个 Animal ,并且这个函数返回一个 Mouse ,也是一个 SmallAnimal 。 既然我们可以安全地,隐式地用前者代替后者,我们可以说 Animal => Mouse 是 Cat =>

Add a header to a tab delimited file

让人想犯罪 __ 提交于 2019-11-28 21:53:28
I'd like to add a header to a tab-delimited file but I am not sure how to do it in one line in linux. Let us say my file is: roger\t18\tcolumbia\tnew york\n albert\t21\tdartmouth\tnew london\n etc... and now I'd like to add a header that says: name\tage\tuniversity\tcity How would I do that in one line in linux? I am ok with awk, sed, cat, etc. not familiar at all with perl though. There isn't a "prepend" operator like the "append" operator >> , but you can write the header to a temp-file, copy your file's contents into the temp-file after that, and move it back: echo -e "name\tage\tuniversity

ES 部分API

若如初见. 提交于 2019-11-28 19:54:24
查看集群的健康状态 curl -XGET http://192.168.1.93:9200/_cat/health?v 查询所有的节点 curl -XGET http://192.168.1.93:9200/_cat/nodes?v 查询所有的索引 curl -XGET http://192.168.1.93:9200/_cat/indices?v 统计es索引信息下的文档数量curl -XGET 'http://192.168.1.93:9200/_cat/count' 统计某个索引信息下的文档数量 curl -XGET 'http://192.168.1.93:9200/_cat/count/api-core-2015.12.31' 查看某一类索引 curl -XGET 'http://192.168.1.93:9200/_cat/indices/api-core-*?pretty' 查看某个索引的健康状态 curl -s http://192.168.1.93:9200/_cat/indices/IndexName?h=status 查看所有关闭的索引 curl -XGET http://192.168.1.93:9200/_cat/indices | awk '$1=="close"' 打开某个关闭的索引 curl -X POST "192.168.1.93:9200

SHELL脚本PPT脚本

元气小坏坏 提交于 2019-11-28 18:17:09
SHELL脚本PPT脚本 在能用的前提上再往好里写 1、判断/var/目录下所有文件的类型 [root@linux1 scripts]# cat filetype.sh #!/bin/bash for i in $(find /var);do if [ -b $i ];then echo "$i 是块设备" elif [ -c $i ];then echo "$i是字符设备" elif [ -f $i ];then echo "$i 是普通文件" elif [ -d $i ];then echo "$i 是目录文件" elif [ -S $i ];then echo "$i 是socket文件" elif [ -L $i ];then echo "$i 是软链接文件" else echo "文件不存在" fi done 2、九九乘法表 [root@linux1 scripts]# cat 9x9.sh RED="\033[0;31m" GREEN="\033[0;32m" NO_COLOR="\033[0m" for i in {1..9};do RANDOM_NUMBER=$[${RANDOM}%7+31] for j in `seq $i`;do echo -e "\033[0;${RANDOM_NUMBER}m${j}x${i}=$[$i*$j]\t\c" done echo

js 继承方式

半腔热情 提交于 2019-11-28 18:10:37
JS作为面向对象的弱类型语言,继承也是其非常强大的特性之一。 需要实现继承必须现有父类,首先定义一个父类。 12345678910111213 function (name) { this.name = name || 'Animal'; // 实例方法 this.sleep = function(){ console.log(this.name + '正在睡觉!'); }}// 原型方法Animal.prototype.eat = function(food) { console.log(this.name + '正在吃:' + food);}; 1. 原型链继承 核心: 将父类的实例作为子类的原型 1234567891011121314151617 function Cat(){ }Cat.prototype = new Animal();Cat.prototype.name = 'cat';// Test Codevar cat = new Cat();console.log(cat.name);console.log(cat.eat('fish'));console.log(cat.sleep());console.log(cat instanceof Animal); //true console.log(cat instanceof Cat); //true

查询无限极分类

烈酒焚心 提交于 2019-11-28 17:26:36
1 /** 2 * User: finn.lee 3 * Date: 2016/3/5 14:25 4 */ 5 $rows = array( 6 0=>array( 7 'cat_id' => 1, 8 'name' => 'dev', 9 'pid' => 0 10 ), 11 1=>array( 12 'cat_id' => 2, 13 'name' => 'php', 14 'pid' => 1 15 ), 16 2=>array( 17 'cat_id' => 3, 18 'name' => 'smarty', 19 'pid' => 2 20 ), 21 3=>array( 22 'cat_id' => 4, 23 'name' => 'life', 24 'pid' => 0 25 ), 26 4=>array( 27 'cat_id' => 5, 28 'name' => 'pdo', 29 'pid' => 2 30 ), 31 5=>array( 32 'cat_id' => 6, 33 'name' => 'pdo-mysql', 34 'pid' => 5 35 ), 36 6=>array( 37 'cat_id' => 7, 38 'name' => 'java', 39 'pid' => 1 40 ) 41 ); 42 43 // 72648 44 /

Recursive cat all the files into single file

回眸只為那壹抹淺笑 提交于 2019-11-28 16:58:31
I have bunch of files sitting in folders like data\A\A\A\json1.json data\A\A\A\json2.json data\A\A\B\json1.json ... data\Z\Z\Z\json_x.json I want to cat all the jsons into one single file? find data/ -name '*.json' -exec cat {} \; > uber.json a short explanation: find <where> \ -name <file_name_pattern> \ -exec <run_cmd_on_every_hit> {} \; \ > <where_to_store> Use find to get all the JSON files and concatenate them. find data -name '*.json' -exec cat {} + > all.json Note that this will not be valid JSON. If you want a JSON file to contain multiple objects, they need to be in a containing array

理解Java方法增强

谁说我不能喝 提交于 2019-11-28 14:59:36
在实际开发中,我们往往需要对某些方法进行增强,常用的方法增强的方式有三种。 类继承 、方法覆盖 必须控制对象创建,才能使用该方式 装饰者模式方法加强 必须和目标对象实现相同接口或继续相同父类,特殊构造器(传入被包装对象) 动态代理 我们来编写一个案例感受一下,新建一个Java项目。 新建类Cat public class Cat{ public void run(){ System.out.println("喵喵~一只猫在奔跑"); } } 现在若想对该类的run()方法进行增强,第一种方法,利用类继承,方法覆盖。 编写测试代码 @Test public void demo1(){ //方法增强的第一种途径,利用类的继承以及方法覆盖 Cat cat = new Cat(){//匿名内部类 @Override public void run() { //保持方法原有的功能 super.run(); //新增该方法功能 System.out.println("抓到一只老鼠"); } }; cat.run(); } 运行测试代码 方法成功被增强了。 该种增强方法的方式必须控制对象的创建。 那么第二种增强方式就是装饰者模式,但是请注意,使用该方式增强方法是有前提的,就是必须与原对象去实现相同的接口或者继承相同的类。 演示一下。 新建一个接口ICat interface ICat{

Reproduce the Unix cat command in Python

喜夏-厌秋 提交于 2019-11-28 11:15:18
I am currently reproducing the following Unix command: cat command.info fort.13 > command.fort.13 in Python with the following: with open('command.fort.13', 'w') as outFile: with open('fort.13', 'r') as fort13, open('command.info', 'r') as com: for line in com.read().split('\n'): if line.strip() != '': print >>outFile, line for line in fort13.read().split('\n'): if line.strip() != '': print >>outFile, line which works, but there has to be a better way. Any suggestions? Edit (2016): This question has started getting attention again after four years. I wrote up some thoughts in a longer Jupyter