cat

Why does reading and writing to the same file in a pipeline produce unreliable results?

萝らか妹 提交于 2019-11-26 22:26:44
问题 I have a bunch a files that contain many blank lines, and want to remove any repeated blank lines to make reading the files easier. I wrote the following script: #!/bin/bash for file in * ; do cat "$file" | sed 's/^ \+//' | cat -s > "$file" ; done However, this had very unreliable results, with most files becoming completely empty and only a few files having the intended results. What's more, the files that did work seemed to change randomly every time I retried, as different files would get

hibernate HQL

大兔子大兔子 提交于 2019-11-26 21:50:01
Hibernate配备了一种非常强大的查询语言,这种语言看上去很像SQL。但是不要被语法结构 上的相似所迷惑,HQL是非常有意识的被设计为完全面向对象的查询,它可以理解如继承、多态 和关联之类的概念。 15.1. 大小写敏感性问题 除了Java类与属性的名称外,查询语句对大小写并不敏感。 所以 SeLeCT 与 sELEct 以及 SELECT 是相同的,但是 org.hibernate.eg.FOO 并不等价于 org.hibernate.eg.Foo 并且 foo.barSet 也不等价于 foo.BARSET 。 本手册中的HQL关键字将使用小写字母. 很多用户发现使用完全大写的关键字会使查询语句 的可读性更强, 但我们发现,当把查询语句嵌入到Java语句中的时候使用大写关键字比较难看。 15.2. from子句 Hibernate中最简单的查询语句的形式如下: from eg.Cat 该子句简单的返回 eg.Cat 类的所有实例。 通常我们不需要使用类的全限定名, 因为 auto-import (自动引入) 是缺省的情况。 所以我们几乎只使用如下的简单写法: from Cat 大多数情况下, 你需要指定一个 别名 , 原因是你可能需要 在查询语句的其它部分引用到 Cat from Cat as cat 这个语句把别名 cat 指定给类 Cat 的实例,

Can I programmatically “burn in” ANSI control codes to a file using unix utils?

我是研究僧i 提交于 2019-11-26 20:58:42
Example: I start recording with script , and try to type echo test but omit the o, so I backspace to correct it. When I cat typescript everything looks normal, since the codes are interpreted, but if I use less or vim I see ech test^H^[[K^H^[[K^H^[[K^H^[[K^H^[[Ko test^M I fully understand what this is and why it's happening, but is there any way to "burn in" the codes and just see the result in a file? My kludgy method is to cat the file, then copy/paste the text out of the terminal, but surely some combination of cat, sed, awk, or something else can get me there more easily? The suggested

Linux cat命令

两盒软妹~` 提交于 2019-11-26 20:25:49
cat命令是linux下的一个文本输出命令,通常是用于观看某个文件的内容的; cat主要有三大功能: 1.一次显示整个文件。 $ cat filename 2.从键盘创建一个文件。 $ cat > filename 只能创建新文件,不能编辑已有文件. 3.将几个文件合并为一个文件。 $cat file1 file2 > file cat具体命令格式为 : cat [-AbeEnstTuv] [--help] [--version] fileName 说明:把档案串连接后传到基本输出(屏幕或加 > fileName 到另一个档案) 参数: -n 或 –number 由 1 开始对所有输出的行数编号 -b 或 –number-nonblank 和 -n 相似,只不过对于空白行不编号 -s 或 –squeeze-blank 当遇到有连续两行以上的空白行,就代换为一行的空白行 -v 或 –show-nonprinting 范例: cat -n linuxfile1 > linuxfile2 把 linuxfile1 的档案内容加上行号后输入 linuxfile2 这个档案里 cat -b linuxfile1 linuxfile2 >> linuxfile3 把 linuxfile1 和 linuxfile2 的档案内容加上行号(空白行不加)之后将内容附加到linuxfile3 里。 范例

tr cat more less head tail 等常用命令

大憨熊 提交于 2019-11-26 20:16:56
# cat 命令: 创建文件 , 显示内容 , 一个不存在的文件或者字符不能输入使用<的输出重定向 。 cat filename 一次显示整个文件 cat > filename 从键盘创建一个文件 cat file1 file2 > file 将几个文件合并为一个文件 cat -n linuxfile1 > linuxfile2 把 linuxfile1 的档案内容 加上行号 后输入 linuxfile2 这个档案里 cat -b linuxfile1 linuxfile2 >> linuxfile3 把 linuxfile1 和 linuxfile2 的档案内容加上行号 ( 空白行不加 ) 之后将内容附加到 linuxfile3 里。 把 linuxfile1 的档案内容加上行号后输入 linuxfile2 这个档案里 cat -n linuxfile1 > linuxfile2 把 linuxfile1 和 linuxfile2 的档案内容加上行号 ( 空白行不加 ) 之后将内容附加到 linuxfile3 里。 cat -b linuxfile1 linuxfile2 >> linuxfile3 cat /dev/null > /etc/test.txt 此为清空 /etc/test.txt 档案内容 cat <<boy >test.sh 内容 boy (直到输入到 boy

11、shell_sed

*爱你&永不变心* 提交于 2019-11-26 19:38:58
正则表达式 正则表达式,就是用一种模式,去匹配一类字符串的公式。 正则表达式的解释是用正则表达式引擎来实现的,常用正则表达式引擎有两类: 基本正则、扩展正则。 正则表达式基础: 正则表达式是由一些普通字符和元字符组成。 元字符不再表示字符本身,而代表一些特定控制意义。 正则表达式元字符: 基本正则: ^ $ . * [] \ \{n,m\} 扩展正则: ? + | {n,m} () ^ 表示开头 ^a 以a开头 ^b 以b开头    例:显示以 r开头的用户名 cut -d: -f1 /etc/passwd | grep ^r   例:显示不以 r开头的用户名 cut -d: -f1 /etc/passwd | grep -v "^r"    例:显示 httpd 或 vsftpd 的配置文件,去掉注释 $ 表示结尾 a$ 表示以a结尾 b$ 以b结尾   例:查看本机不允许登录的用户 cat /etc/passwd | grep "nologin$" . 任意字符       例:第 2个字符是a .a * 零个或多个   例 : 查看每行至少含有2个或以a的行 cat test.txt | grep aaa* [] 字符范围 例:以 a或b开头的行 cat test.txt | grep "^[ab]" 例:显示以数字开头的行 cat test.txt | grep ^

(13)mongodb 聚集运算之 group

佐手、 提交于 2019-11-26 19:30:14
mongodb 有3个方法实现数据的分析与统计,分别是group()分组统计、aggregate()简单聚合、mapReduce()强大统计。group 函数需要自己实现逻辑,所以它很灵活,但是有一个缺点就是不支持分片,不支持数据的分布式运算,在下面的章节中再分析支持share分片的方法。下面先说一下 group 函数的语法构成: db.collection.group(document) document格式: { key:{key1:1,key2:1}, cond:{}, reduce:function(curr,result){ }, initial:{}, finalize:function(){ } } 说明: key:分组字段,是对谁进行分组,相当于关系型数据库中的group by。 cond:查询条件,相当于where。 reduce:聚合函数,是自己的实现逻辑,也就是在分组的结果中做什么。 initial:初始化,可以理解为进入分组先做什么。 finalize:统计一组后的回调函数,理解为跳出分组后做什么,在reduce后执行。 下面用具体列子说明。 1、准备数据:将下面31条数据写入shop库的goods表 [{"goods_id":1,"cat_id":4,"goods_name":"KD876","goods_number":1,"click_count":7

SVN commit failed: 'xxx' is not under version control

纵饮孤独 提交于 2019-11-26 18:34:54
svn commit -m ` cat /tmp/sometext` 报错commit failed: 'xxx' is not under version control 原来是shell命令外面忘记加引号了。。。 svn commit -m " `cat /tmp/sometext` " 顺利提交 转载于:https://www.cnblogs.com/Leo-Forest/archive/2012/07/24/2605951.html 来源: https://blog.csdn.net/weixin_30706691/article/details/99022631

[UNIX][OS] os version

[亡魂溺海] 提交于 2019-11-26 18:22:46
1. Linux 版號 cat /proc/version 2. CentOS version cat /etc/*release cat /etc/redhat-release 3. uname -a ( 2017/05/10 更新 ) [vl97@ST01APTN01 ~]$ uname -a Linux ST01APTN01 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux 转载于:https://www.cnblogs.com/vincentmylee/archive/2013/02/20/2918108.html 来源: https://blog.csdn.net/weixin_30549175/article/details/99011519

Preserving leading white space while reading>>writing a file line by line in bash

依然范特西╮ 提交于 2019-11-26 17:08:34
问题 I am trying to loop through a directory of text files and combine them into one document. This works great, but the text files contain code snippets, and all of my formatting is getting collapsed to the left. All leading whitespace on a line is stripped. #!/bin/sh OUTPUT="../best_practices.textile" FILES="../best-practices/*.textile" for f in "$FILES" do echo "Processing $f file..." echo "">$OUTPUT cat $f | while read line; do echo "$line">>$OUTPUT done echo >>$OUTPUT echo >>$OUTPUT done I am