grep

Using grep and sed to find and replace a string

走远了吗. 提交于 2020-01-26 21:54:12
问题 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

Using grep and sed to find and replace a string

删除回忆录丶 提交于 2020-01-26 21:54:06
问题 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

Linux shell命令总结大全

不想你离开。 提交于 2020-01-26 19:23:46
关机/重启 关机(必须用root用户) shutdown -h now ## 立刻关机 shutdown -h +10 ## 10分钟以后关机 shutdown -h 12:00:00 ##12点整的时候关机 halt # 等于立刻关机 重启 shutdown -r now reboot # 等于立刻重启 echo root@ubuntu:~# a="hello,world" root@ubuntu:~# echo a a root@ubuntu:~# echo &a [1] 3091 a: command not found [1]+ Done echo root@ubuntu:~# echo $a hello,world root@ubuntu:~# vim文本编辑器 最基本用法 vi somefile.4 1 首先会进入“一般模式”,此模式只接受各种快捷键,不能编辑文件内容 2 按i键,就会从一般模式进入编辑模式,此模式下,敲入的都是文件内容 3 编辑完成之后,按Esc键退出编辑模式,回到一般模式; 4 再按:,进入“底行命令模式”,输入wq命令,回车即可 常用快捷键 一些有用的快捷键(在一般模式下使用): a 在光标后一位开始插入 A 在该行的最后插入 I 在该行的最前面插入 gg 直接跳到文件的首行 G 直接跳到文件的末行 dd 删除一行 3dd 删除3行 yy 复制一行

adb logcat 日志打印手册

浪尽此生 提交于 2020-01-26 11:20:16
/*--> */ /*--> */ 清除终端 log 缓存: adb logcat -c -b main -b events -b radio -b system -b crash adb Bug 定位过滤: 1. 查看 logcat 信息: adb logcat adb logcat --help ——> 帮助 grep 命令 : 用于过滤 / 搜索的特定字符 grep --help ——> 查看 grep 帮助 -E ——> 指定字符串做为查找文件内容的样式,一个可扩展的正则表达式; -r ——> 指定要查找的目录或文件 ( 默认当前目录 ) ; -i ——> 忽略字符大小写; -v ——> 显示不包含匹配文本的所有行 ( 剔除 ) ; -l ——> 显示符合指定的内容样式的文件名称; -n ——> 显示行数编号; 指定文件 : grep "tag" ./filename grep "tag" ——> 过滤带有 tag 的字符串 grep -E "tag1|tag2|..." ——> 过滤带有 tag1|tag2|... 的字符串 grep -i "tag" ——> 忽略 tag 大小写 grep -i -E "tag1|tag2|..." ——> 忽略 tag1|tag2|... 大小写 grep -v "tag" ——> 剔除不符合条件 tag 的 log grep -v

use text and use as command?

假如想象 提交于 2020-01-26 04:16:23
问题 i whant to build a script to extract the word from a file in a command: for example: in my file i keep my username , how can i export the username without knowing the username as part of my command , which my command is : suspend here should be the word exported? From my file which has the text inside "JOHN" how can i tell the command : suspend that the username is JOHN ? how can i cat/grep/sed the text from the file as part of command : something like suspend |cat file , i have try that but

redis哨兵、集群

对着背影说爱祢 提交于 2020-01-26 02:10:05
cd /opt/s18msredis/ 1016 vim redis-6379.conf 1017 cat redis-6380.conf 1018 redis-server redis-6379.conf 1019 redis-server redis-6380.conf 1020 redis-server redis-6381.conf 1021 ps -ef|grep redis 1022 redis-cli -p 6379 1023 redis-cli -p 6380 1024 redis-cli -p 6381 info replication 1025 redis-cli -p 6381 1026 redis-cli -p 6379 1027 redis-cli -p 6381 1028 ps -ef|grep redis 1029 kill -9 18319 1030 ps -ef|grep redis 1031 redis-cli -p 6381 1032 redis-cli -p 6380 1033 redis-cli -p 6381 1034 ps -ef|grep redis 1035 pkill redis-server 1036 rm -rf /data/* 1037 mkdir -p /data/{6379,6380,6381} 1038 redis

linux文本处理工具之grep与正则表达式语法

你说的曾经没有我的故事 提交于 2020-01-25 22:36:37
Grep 介绍 Linux 文本处理三剑客之一,文件过滤工具(另外两剑客为 sed :文本编辑工具, awk :文本报告生成器) 拥有着,根据用户指定的“模式”对目标文本逐行进行匹配检查;打印匹配到的行的功能。 使用 Grep 除了正常的字符使用之外 还可以运用正则表达式字符。 Grep 的重要命令选项 --color=auto 关键字高亮显示( centos7 默认) *-v 关键字 显示不包含关关键字的行,取反 *-i 关键字 忽略关键字的大小写 -n 显示的结果每行前增加行号 -c 仅显示找出的结果的行数 *-o 仅显示匹配到的关键字,不显示同行的其他内容 *-w 关键字 匹配整个单词 *-E 等于 egrep 使用扩展正则表达式 正则表达式 正则表达式 regexp 又称规则表达式,是由一类特殊字符及文本编写的,其中有些字符有些字符(元字符)不表示字符字面意义,而表示控制或通配的功能。 就是用事先定义好的一些特定字符、及这些特定字符的组合,组成一个 “规则字符串”,这个“规则字符串”用来表达对字符串的一种过滤逻辑。正则表达式是一种 文本模式 ,模式描述在搜索文本时要匹配的一个或多个字符串 。 正则表达式的使用 具有特殊意义的字符元字符有着 字符匹配,匹配次数、位置锚定、分组四个功能。掌握了这四个功能 在运用正则表达式的时候会事半功倍 以下四个功能处理的都是元字符。 1.

Curl and grep status code and content of the file

假装没事ソ 提交于 2020-01-25 14:26:42
问题 Is there way to curl and grep for an expression while matching a first line (which contains status code) using grep? (Without saving the result of the curl on a file or a variable.) I am thinking some thing like this but using grep - curl -is "http://example.com/test.html" | awk 'NR == 1 || /'"JOB_STATUS"'/' using maybe head and grep head -n 1 and grep -E "exp[ab]" 回答1: If your curl output looks something like this: Status:200 something ... something JOB_STATUS you can use: curl ... | egrep

springboot项目启动与停止命令

安稳与你 提交于 2020-01-25 14:23:38
start(){ ps aux | grep nginx | grep -v grep | awk '{print $2}' | xargs kill -9 ps aux | grep appserver-0.0.1-SNAPSHOT.jar | grep -v grep | awk '{print $2}' | xargs kill -9 /usr/sbin/nginx -c /etc/nginx/nginx.conf nohup java -jar /usr/liuheyoulu/JAR/appserver-0.0.1-SNAPSHOT.jar > /usr/liuheyoulu/JAR/liuheyoulu.out 2>&1 & } stop(){ ps aux | grep nginx | grep -v grep | awk '{print $2}' | xargs kill -9 ps aux | grep appserver-0.0.1-SNAPSHOT.jar | grep -v grep | awk '{print $2}' | xargs kill -9 } case "$1" in "start") start ;; "stop") stop ;; *) esac 重命名为:xxx.sh /usr/liuheyoulu/liuhe_war.sh start

Linux 命令grep

时光总嘲笑我的痴心妄想 提交于 2020-01-25 08:22:59
grep options -i --ignore case忽略大小写 -v --invert-match反转匹配 -c --count 统计匹配数值 -l --files-with-matches 输出包含关键字的文件 -L --files-without-matches 输出不包含关键字的文件 -n --line-number 打印行号 通配符 ^ $ . [ ] { } - ? * + ( ) | \ ^ $ 锚定位符 可以理解为锚点,就是以^开始,以$结束的匹配,例如 grep ‘^ zip $’ abc.txt 只会匹配到一行中的 zip 关键字 . 点表达式 点的用法匹配aa文件中的单词第三个字母是j最后一个字母是r 例如 grep -i '^..j.r$' aa.txt [] 括号表达式 括号中的关键字只要匹配到一个字母即可,例如 grep '[ab]zip' aa.txt 可以匹配到 azipxxx,bzipyyy等 和^组合使用 grep '[^ab]zip' aa.txt 就是反向输出结果匹配到 bunzip2 ,gunzip ,funzip - 破折号 想要匹配到文件中以大写字母开头的关键词,可以这样表达 grep -h '^[ABCDEFGHIJKLMNOPQRSTUVWXZY]' dirlist*.txt 简化一下可以这样写 grep -h '^[A-Y]'