grep

grep -f file to print in order as a file

怎甘沉沦 提交于 2020-01-29 12:11:46
问题 I have a a requirement to grep patterns from a file but need them in order. $ cat patt.grep name1 name2 $ grep -f patt.grep myfile.log name2:some xxxxxxxxxx name1:some xxxxxxxxxx I am getting the output as name2 was found first it was printed then name1 is found it is also printed. But my requirement is to get the name1 first as per the order of patt.grep file. I am expecting the output as name1:some xxxxxxxxxx name2:some xxxxxxxxxx 回答1: You can pipe patt.grep to xargs , which will pass the

常见命令用法总结

强颜欢笑 提交于 2020-01-29 11:24:40
目录: 1、关于grep的总结 2、关于egrep的总结 3、关于tr的总结 4、关于sort的总结 5、关于uniq的总结 6、关于cut的总结 7、关于tee的总结 8、关于split的总结 9、关于type的使用 10、关于find的使用 11、关于xargs的使用 关于grep的总结 找出所需字符串的时候可用引号也可以不用引号。 1、grep bc test 2、grep "bc" test 3、grep 'bc' test 注:以上3中形式都能找出test文件中相对应含有字符串bc的行并打印出来。 比较常用的参数有; -i, --ignore-case 忽略大小写 -n, --line-number print line number with output lines -v, --invert-match select non-matching lines 显示不匹配的行 -h, --no-filename suppress the prefixing filename on output查询多文件时不显示文件名 -l, --files-with-matches print only names of FILEs containing matches查询多文件时只显示文件名 grep select * ,列出当前目录下所有包含select

Linux 基本命令

断了今生、忘了曾经 提交于 2020-01-29 08:57:19
下面是我学习linux的一些笔记,整理总结如下 首先先普及一下常识:DNS是用来解析域名的;url端口默认是80,可以不写;localhost 就是127.0.0.1,如果是root时,提示符为:# ,普通用户则为:$; Linux下常用命令: 1.查看当前系统下登录的用户时,可以输入whoami命令,如果想查看系统下总共有几个用户的话,可以在/home路径下查看; 2.查看当前系统ip信息,可以输入ip a, 3.修改临时ip地址,可以输入ifconfig eth0 169.254.*.*,但是重启之后失效; 4.netstat -nlpt|grep 80 查看端口号有没有被占用; 5.ps -ef|grep mysql ps -ef查找进程 grep 显示文件中的匹配行;ps -ef|grep httpd |grep -v "grep" -v 是指把grep进程排除掉;ps是瞬时的,top是动态的 6.环境变量 修改环境变量时,要记得写$PATH: ,我当时在linux上装tomcat的时候就忘记写$PATH:了,导致系统启动报错, 7.cd .. 返回上一级目录,cd ../../.. 回到上三级目录,cd - 回到上一次操作的目录,知道这些命令在来回切换目录的时候就方便多啦 8.scp命令 是在两台机器之间复制传输文件,此处引用一个大拿的博客来介绍,http://www

Linux查看机器是cpu是几核

自闭症网瘾萝莉.ら 提交于 2020-01-29 03:49:32
linux下查看机器是cpu是几核的 几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核(假设cpu配置相同) more /proc/cpuinfo |grep "physical id"|grep "0"|wc -l cat /proc/cpuinfo | grep processor 1. 查看物理CPU的个数 #cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l 2. 查看逻辑CPU的个数 #cat /proc/cpuinfo |grep "processor"|wc -l 3. 查看CPU是几核 #cat /proc/cpuinfo |grep "cores"|uniq 4. 查看CPU的主频 #cat /proc/cpuinfo |grep MHz|uniq # uname -a Linux euis1 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux (查看当前操作系统内核信息) # cat /etc/issue | grep Linux Red Hat Enterprise Linux AS release 4 (Nahant

总结一些常用脚本

白昼怎懂夜的黑 提交于 2020-01-28 08:20:18
1、替换ceph.conf配置文件 if [ -n "`/usr/bin/grep -w paxos_min /etc/ceph/ceph.conf`" ]; then sed -i '/paxos_min/c\paxos_min = 5000' /etc/ceph/ceph.conf; else sed -i '/auth_client_required/a\paxos_min = 5000' /etc/ceph/ceph.conf; fi 2、删除一个root pool_name=xxxx;for i in `ceph osd crush ls "$pool_name"_host_group`;do ceph osd crush rm `ceph osd crush ls "$i"` $i ; done;for i in `ceph osd crush ls "$pool_name"_host_group`;do ceph osd crush rm $i ;done;ceph osd crush rm "$pool_name"_host_group 3、统计所有慢op 原型 ceph daemon osd.1 dump_historic_slow_ops|egrep -w "initiated_at|duration|time|event"|sed -e 's/"//g' -e

linux杀死僵尸进程

不想你离开。 提交于 2020-01-28 01:11:29
ps -A -o stat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}' | xargs kill -9 1、查看系统是否有僵尸进程 使用Top命令查找,当zombie前的数量不为0时,即系统内存在相应数量的僵尸进程。 2、定位僵尸进程 使用命令ps -A -ostat,ppid,pid,cmd |grep -e '^[Zz]'定位僵尸进程以及该僵尸进程的父进程 僵尸进程ID:3457,父进程ID:3425 僵尸进程ID:3533,父进程ID:3511 3、使用Kill -HUP 僵尸进程ID来杀死僵尸进程,往往此种情况无法杀死僵尸进程,此时就需要杀死僵尸进程的父进程 kill -HUP 僵尸进程父ID 然后使用上面的语句查询该僵尸进程是否被杀死 4、参数解读 ps -A -ostat,ppid,pid,cmd |grep -e '^[Zz]' -A 参数列出所有进程 -o 自定义输出字段 stat(状态)、ppid(进程父id)、pid(进程id)、cmd(命令) 因为状态为z或者Z的进程为僵尸进程,所以我们使用grep抓取stat状态为zZ进程 -------------------------------------------------------------------------------------------

每天一个linux命令(1):ls命令

安稳与你 提交于 2020-01-28 00:41:00
ls命令是linux下最常用的命令。ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单。 通过ls 命令不仅可以查看linux文件夹包含的文件而且可以查看文件权限(包括目录、文件夹、文件权限)查看目录信息等等。ls 命令在日常的linux操作中用的很多! 1. 命令格式: ls [选项] [目录名] 2. 命令功能: 列出目标目录中所有的子目录和文件。 3. 常用参数: -a, –all 列出目录下的所有文件,包括以 . 开头的隐含文件 -A 同-a,但不列出“.”(表示当前目录)和“..”(表示当前目录的父目录)。 -c 配合 -lt:根据 ctime 排序及显示 ctime (文件状态最后更改的时间)配合 -l:显示 ctime 但根据名称排序否则:根据 ctime 排序 -C 每栏由上至下列出项目 –color[=WHEN] 控制是否使用色彩分辨文件。WHEN 可以是'never'、'always'或'auto'其中之一 -d, –directory 将目录象文件一样显示,而不是显示其下的文件。 -D, –dired 产生适合 Emacs 的 dired 模式使用的结果 -f 对输出的文件不进行排序,-aU 选项生效,-lst 选项失效 -g 类似 -l,但不列出所有者 -G, –no-group

linux jar的启动和停止

╄→гoц情女王★ 提交于 2020-01-27 01:14:39
jar包的启动 参考文章: https://www.cnblogs.com/longqingyang/p/7017444.html startup.sh nohup java -Xmx1024m -Xms1024m -Dfile.encoding=utf-8 -jar -Dserver.port=8088 xxx.jar& jar包的停止 参考文章: https://blog.csdn.net/esqabc/article/details/91045089 https://blog.csdn.net/shGray/article/details/101350925 stop.sh #!/bin/bash JC=$(ps -ef | grep xxx.jar | grep -v grep |awk '{print $2}') kill $JC 来源: CSDN 作者: Dug_Zhang 链接: https://blog.csdn.net/Dug_Zhang/article/details/103873281

Using grep and sed to find and replace a string

一笑奈何 提交于 2020-01-26 21:57:20
问题 I am using the following to search a directory recursively for specific string and replace it with another: grep -rl oldstr path | xargs sed -i 's/oldstr/newstr/g' This works okay. The only problem is that if the string doesn't exist then sed fails because it doesn't get any arguments. This is a problem for me since i'm running this automatically with ANT and the build fails since sed fails. Is there a way to make it fail-proof in case the string is not found? I'm interested in a one line