栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

linux命令查询,合并,对比,排序文件。

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

linux命令查询,合并,对比,排序文件。

1.最近想补充一些linux命令的对文件内的数据查询,合并,对比等操作。(对操作日志文件比较适用吧)

   find  /home/test/web -type f -atime +3         查看三天前/home/test/web  目录被修改过的所有类型的文件.
   sed -i "s/cheng/test/g" `grep -rl "cheng" /home/cheng/`     (注意grep 前面 和 ./ 后面 是 ```  符号的) 
   sed -i "s/要找查找的文本/替换后的文本/g"  `grep -rl "要找查找的文本" ./`

 以下是对文件内容的操作:(加入文件内有一些比较有规律的数据)  如果在参数后面加上空格则会把结果生成一个新的文件 比如  sort  /homw/test/test.log  |  unique  - c   结果就是 23出现一次 000出现 6次

                去除重复行   sort file |  uniq                 
                sort    /home/test/test.log    |  uniq 

                查找非重复行  sort file | uniq -u           
                sort    /home/test/test.log    |  uniq  -u

                查找重复行  sort file |  uniq -d              
                sort    /home/test/test.log    |  uniq  -d

                统计  sort file | uniq -c                          
                sort    /home/test/test.log    |  uniq -c


                paste file1 file2 合并两个文件或两栏的内容                                       
                paste  test1.log   test2.log 

                paste -d '+' file1 file2 合并两个文件或两栏的内容,中间用"+"区分   
                paste -d '=' test1.log  test2.log

                comm -1 file1 file2 比较两个文件的内容只删除 'file1' 所包含的内容  
                comm -1 test1.log  test2.log

                comm -2 file1 file2 比较两个文件的内容只删除 'file2' 所包含的内容  
                comm -2 test1.log  test2.log

                comm -3 file1 file2 比较两个文件的内容只删除两个文件共有的部分  
                comm -3 test1.log  test2.log









   

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/226828.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号