bashsedawk
文章平均质量分 59
weixin_888988
自动化运维
展开
-
word contain a specific letter
An old (and quite portable) way to do it is using a case statement:var="information"case $var in *i*) echo "An 'i' was found in $var";; * ) echo "There is no 'i' in $var";;esacAs a one line function:a="information" b="i"one(){ cas转载 2021-05-21 09:39:23 · 88 阅读 · 0 评论 -
AWK - Time Functions
AWK - Time FunctionsAdvertisementsAd byValueimpressionPrevious PageNext PageAWK has the following built-in time functions −systimeThis function returns the current time of the day as the number of seconds since the Epoch (1970-01-01 00...转载 2020-10-08 15:23:35 · 86 阅读 · 0 评论 -
sed删除匹配行的上一行和下一行
1.删除匹配行的上一行和下一行:sed -i -e '/string/{n;d}' -e '$!N;/\n.*string/!P;D' file2.sed中使用变量,删除匹配行的上一行和下一行:AA=string #变量指定匹配字符串sed -i -e '/'"$AA"'$/{n;d}' -e '$!N;/\n.*'"$AA"'$/!P;D' file例子:...转载 2020-04-26 15:45:19 · 4740 阅读 · 1 评论 -
sed与[]
[root@cnwbzp3137 aiaanzreport]# sed -r -n "/change.*data[\"all\"]/p" AIAID/views.py return render(request, "aiaidchange.html", {"data": data["Notapprovedle7ds"]}) retur...原创 2020-04-11 20:08:38 · 82 阅读 · 0 评论 -
sed 匹配内容方法
linux系统中,利用grep打印匹配的上下几行如果在只是想匹配模式的上下几行,grep可以实现。//搜索inputfile中满足parttern的内容的行号grep -n 'parttern' inputfile查看某文件inputfile指定行号(90)后的内容$grep -5 'parttern' inputfile //打印匹配行的前后5行$grep -C 5...转载 2020-04-01 20:36:30 · 1907 阅读 · 0 评论 -
sed: the first match or match N time
I want to split a file into chunks with 2 words each.$cat tmpword1 word2 word3 word4 word5 word6 word7$sed -e 's/word. word. /&\n/g' tmpword1 word2 word3 word4 word5 word6 word7s...转载 2020-04-01 20:09:16 · 252 阅读 · 0 评论 -
sed: extract STRING between first occurrence of MATCH1 and next occurrence of MATCH2
Here's asedsolution:echo "abcd MATCH1 STRING MATCH2 efgh MATCH1 ijk MATCH2 MATCH2 lmnop MATCH1" | sed 's/MATCH1/&\n/;s/.*\n//;s/MATCH2/\n&/;s/\n.*//'echo "abcd MATCH1 STRING MAT...原创 2020-04-01 19:52:52 · 89 阅读 · 0 评论 -
sed: replace only the second match word
to change only the second match word ( to replace Allow,Deny with Deny,Allow )sedsolution:Sampletmp_file:Allow,DenyAllow,DenyAllow,DenyAllow,Denysed ':a;N;$!ba; s/Allow,Deny/Deny,Allo...原创 2020-04-01 19:39:59 · 142 阅读 · 0 评论 -
使用sed删除或操作两个pattern模式匹配行之间的内容
使用sed删除两个模式匹配行之间的内容在配置文件中有时候想要把两节之间的内容全部删除,便于修改为新的配置,sed命令如下//删除模式匹配行之间的内容sed -i '/\[section1\]/,/\[section2\]/{/\[section1\]/!{/\[section2\]/!d}}' test.repo说明:1. 中括号需要用转义运算符。 \[sectio...转载 2020-03-12 16:55:07 · 1557 阅读 · 1 评论 -
$IFS
$IFSJump to navigationJump to searchThe IFS is a special shell variable. You can change the value of IFS as per your requirments. TheInternal Field Separator(IFS) that is used for word splitti...转载 2020-03-12 16:50:50 · 218 阅读 · 0 评论 -
sed匹配下N行,前一行和后一行,添加内容
测试文件 test.log[root@localhost aaa]# cat test.log a 1 11 aa 2 22 b 3 33 a 4 44 匹配出以a开头并以a结尾的后1行:sed-n'/^a$/,+1p'test.log输出结果:a 1 ...转载 2019-12-12 08:30:00 · 2903 阅读 · 1 评论