首页 > 代码库 > linux shell常用命令
linux shell常用命令
for循环
applist=(app1 app2 app3);for app in ${applist[@]};do echo $app;done;
获取IP地址
ifconfig |grep -Po ‘(?<=addr:).*(?=Bc)‘
ifconfig|awk -F"[: ]+" ‘$4~/[0-9].+[^0-9]+/{print $4}/lo/{exit}‘
ifconfig|sed -nr ‘s/^[[:space:]]+inet addr:(.*) Bcast.*/\1/p‘
ifconfig | grep -o ‘\([1-9]\{1,3\}\.\)\{3\}[0-4]\{3,\}‘
格式化输出文档
cat xxxx | awk ‘{print "n"NR"="$1,"m"NR"="$2}‘|column -t 将格式化输出文档
输出某段时间内的日志
sed -n ‘/2015-07-27 11:00/,/2015-07-27 11:20/p‘ xxx_server_log > dsadsads.log
sed -n ‘/06\/Dec\/2016:20:30:00/,/06\/Dec\/2016:21:00:00/p‘ json_access.log.2016-12-06 > dsadsads.log #加了转义
echo不换行输出
echo -n "xx";
awk或者echo中输出换行符或者Tab键
echo -e "123\t345" > /tmp/123.txt;cat /tmp/123.txt | awk ‘{ print $1 "\t,\n" $2 }‘
待续
本文出自 “梦里不知身是客” 博客,请务必保留此出处http://tenfee.blog.51cto.com/6353835/1918958
linux shell常用命令