cat

梳理一下 JavaScript 中的继承

一曲冷凌霜 提交于 2019-11-27 08:55:16
梳理 JavaScript 中的继承问题,则不得不先理解 Js 中的原型链,因为 ECMAScript 主要是基于原型链实现继承的。 原型链 在 Js 中,每个函数都有一个 prototype 属性,其指向该函数的原型对象。而函数的原型对象中,有一个 constructor 属性,指回向该函数。当函数被当作构造函数,使用 new 运算符生成实例时,在生成的实例对象中有一个内部属性 __proto__ 属性,该属性也指向函数的原型对象。在原型对象上有 __proto__ 指向原型对象的原型对象,依次传递,直到指向 Object.prototype 对象为止,即构成了原型链。如下图所示: 原型链继承 function Animal(name) { this.name = name; this.colors = ['black', 'red', 'pink']; } Animal.prototype.run = function (){ console.log('running'); } function Cat(age) { this.age = age; } Cat.prototype = new Animal('cat'); // 实现原型链继承 var cat1 = new Cat(1); console.log(cat1); // Cat { // age: 1, // _

linux管道和tee命令

こ雲淡風輕ζ 提交于 2019-11-27 07:52:26
ps -ef | grep docker 等价于 ps -ef &> >(grep docker) cat a.log | tee b.txt 等价于 cat a.log &> >(tee b.txt) cat a.log | md5sum > a.sum 为了将过程打印到屏幕 cat a.log | tee >(md5sum > a.sum) 从而 cat a.log |tee >(md5sum > a.sum) > b.txt 既可以对数据流做md5sum, 又可以做重定向 cat a.log |tee >(md5sum > a.sum) | tee b.txt md5sum + 屏幕打印 + 写文件 来源: https://www.cnblogs.com/mhc-fly/p/11352028.html

Reproduce the Unix cat command in Python

六月ゝ 毕业季﹏ 提交于 2019-11-27 05:59:57
问题 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

Linux中查看文件内容的命令(cat,more,less,head,tail)

旧巷老猫 提交于 2019-11-27 05:31:42
cat命令 用途:显示出文件的内容 cat [选项] 文件名... 示例 [root@localhost ~]# cat /etc/hosts [root@localhost ~]# cat /etc/sysconfig/network 缺点:在字符界面中,如果内容超过屏幕显示的最大行数,则只会显示最后能显示的行数。 more命令 用途:全屏方式分页显示文件内容 more [选项] 文件名... 交互操作方式 按Enter键向下逐行滚动。 按空格键向下翻一屏 按q键退出 缺点:当翻到行尾时再翻页会自动退出,无法再向上翻页。 less命令 用途:与more命令相同,但扩展功能更多 less [选项] 文件名... 交互操作方式 Page Up 向上翻页, Page Down向下翻页 按"/"键查找内容,"n"下一个内容,"N"上一个内容 其他功能与more命令基本类似 head命令 用途:查看文件开头的一部分内容(默认为10行) head -n 文件名... tail命令 用途:查看文件结尾的少部分内容(默认为10行) tail -n 文件名... 或 tail -n 文件名... 来源: https://blog.51cto.com/14449798/2429181

cat命令

*爱你&永不变心* 提交于 2019-11-27 05:18:05
cat命令本来用于连接多个文件的内容,但在实际使用中更多地用于查看文件内容,它常与重定向符合配合使用。 1.命令格式: cat [选项] [文件] 2.命令功能: cat主要有三大功能 1.一次显示整个文件 2.从键盘创建一个文件 3.将几个文件合并一个文件 3.常用命令参数 -A, all -b,对非空输出行编号 -n,对输出的所有行编号,由1开始对所有输出的行数编 -s,有连续两行以上的空白行,就代换为一行的空白行 4.使用实例 实例一:查看/opt/test1.txt 命令: cat /opt/test1.txt 实例二:用cat创建一个文件test2.txt(在/opt目录下),并且内容为:my name is cat 命令:cat >test2.txt . 实例三:同时查看test1.txt文件和test2.txt文件 命令 cat /opt/test1.txt /opt/test2.txt 实例四:将test1和test2文件的内容合并到一个新文件test3中 命令:cat /opt/test1.txt /opt/test2.txt >test3 来源: https://blog.51cto.com/14449563/2429165

Shell脚本之sed的使用

让人想犯罪 __ 提交于 2019-11-27 04:45:38
1.sed命令;主要作用是查找;新增 删除 和修改替换。 user.txt daokr#cat user.txt ID Name Sex Age 1 zhang M 19 2 wang G 20 3 cheng M 10 4 huahua M 100 查找命令:-n 和 p(print) 在user.txt文件中;匹配带h的行 并且只显示1,3行 cat user.txt | grep h |sed -n '1,3p' daokr#cat user.txt | grep h |sed -n ' 1,3p ' 1 zhang M 19 3 cheng M 10 4 huahua M 100 删除命令:d(delete) 删除最后一行记录 cat user.txt | grep h | sed '$d' 在user.txt中显示带h的行;并且从结果中删掉2,3行的记录;只看第一行记录 cat user.txt | grep h |sed '2,3d' daokr#cat user.txt | grep h 1 zhang M 19 3 cheng M 10 4 huahua M 100 daokr#cat user.txt | grep h |sed ' 2,3d ' 1 zhang M 19 新增数据:a (append) 在user.txt中查询出带h的行

正则宏替换

旧城冷巷雨未停 提交于 2019-11-27 04:13:38
find ./ -name .c -exec grep -E '^\s #if|^\s*#elif' {} ; > ./tmp 找宏 cat ./tmp | grep -E '^\s #[^\\/]+' -o >> ./tmp2 找各行#后面不是接//注释的 cat ./tmp | grep -E '^\s #[^\\/]+' -o | sed -r 's!&&|||!\n!g' >> ./tmp3 使用!代替/进行替换,但要转义|| cat ./tmp | grep -E '^\s #[^\\/]+' -o | sed -r 's!&&|||!\n!g' | sed -r 's!# [a-z]+ | defined | \( |\) | \s+ | ! | [0-9] \s* (> | < | = | <= | >= | ==) \s [0-9] | \s* | "!g' cat ./tmp3 | sed -r 's! #[a-z]+ | defined | \( | \) | \s+ | ! | [0-9] \s (> | < | = | <= | >= | ==)\s [0-9] | \s* | " !!g ' >> ./tmp4 cat ./tmp4 | sed -r '/^(0|1)?$$/d' >> ./tmp5 cat ./tmp5 | sort -u >> .

linux常用的shell文本处理方法

拥有回忆 提交于 2019-11-27 03:09:45
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 按大小搜索:w字 k M G寻找大于2k的文件 find . -type f -size +2k 按权限查找: find . -type f -perm 644 -print //找具有可执行权限的所有文件 按用户查找: find . -type f -user weber -print// 找用户weber所拥有的文件 找到后的后续动作 删除

【M33】将非尾端类设计为抽象类

妖精的绣舞 提交于 2019-11-27 01:16:52
1、考虑下面的需求,软件处理动物,Cat与Dog需要特殊处理,因此,设计Cat和Dog继承Animal。Animal有copy赋值(不是虚方法),Cat和Dog也有copy赋值。考虑下面的情况: Cat cat1; Cat cat2; Animal *a1 = &cat1; Animal *a2 = &cat2; *a1 = *a2; 思考*a1 = *a2会有什么问题? copy赋值不是虚方法,根据表面类型,调用Animal的copy赋值,这就导致所谓的部分赋值,cat2的Animal成分赋值给cat1的Animal成分,二者的Cat成分保持不变。 2、怎么解决上面的问题? 将Animal的copy赋值声明为virtual方法,如下: virtual Animal& operator=(const Animal &rhs); Cat和Dog重写: virtual Cat& operator=(const Animal &rhs); virtual Dog& operator=(const Animal &rhs); 这里使用了C++语言后期的一个特性,即协变,返回的引用更加具体。但是,对于形参表,重写必须保证保持一致。将copy赋值声明为virtual,解决了部分赋值的问题。但是,引入了一个新的问题。如下: Cat cat; Dog dog; Animal* a1 = &cat;