shell 获得字符串所在行数及位置
01 获取字符串所在的行数
方式一:用grep -n
[root@root]# cat test
apple
bit
create
delect
exe
flow
good
[root@root]# cat test | grep -n exe
5:exe
[root@root]# cat test | grep -n exe | awk -F ":" '{print $1}'
5
方式二:用sed -n '/查询的字符串/=' 文件
[root@root]# cat test
apple
bit
create
delect
exe
flow
good
[root@root]#
[root@root]# sed -n '/exe/=' test
5
02 获取字符串中字符所在的位置
方式一:用awk -F 和 wc -c 组合
[root@root]# echo 'uellevcmpottcap' | awk -F 'ott' '{print $1}';
uellevcmp
[root@root]# echo 'uellevcmpottcap' | awk -F 'ott' '{print $1}' | wc -c
10
方式二:用awk 'BEGIN{print index("'${str}'","'${str1}'") }'
[root@root]# str='uellevcmpottcap';str1='ott';awk 'BEGIN{print index("'${str}'","'${str1}'") }'
10
Linux Shell 截取字符串
Linux Shell 截取字符串 shell中截取字符串的方法很多 ${var#*/} ${var##*/} ${var%/*} ${var%%/*} ${var:start:len} ${var: ...
Linux shell去除字符串中所有空格
Linux shell去除字符串中所有空格 echo $VAR | sed 's/ //g'
Linux Shell多进程并发以及并发数控制
1. 基础知识准备 1.1. linux后台进程 Unix是一个多任务系统,允许多用户同时运行多个程序.shell的元字符&提供了在后台运行不需要键盘输入的程序的方法.输入命令后,其后紧跟&a ...
Linux shell 判断字符串为空等常用命令
1.判断字符串为空 if [ -z "$str" ]; then echo "empty string" fi 2.判断文件是否存在 if [ -f /home ...
Linux shell 将字符串分割成数组
原文链接:http://1985wanggang.blog.163.com/blog/static/776383320121745626320/ a="one,two,three,four& ...
[转+整理]linux shell 将字符串分割成数组
原文链接:http://1985wanggang.blog.163.com/blog/static/776383320121745626320/ a="one,two,three,four& ...
linux shell: 搜索字符串,剔除包含特定字符的行
搜索代码中出现CONFIG_BOOTARGS的行,但又不希望有#define和#undef, 暂时不知带如何直接用一个语句做到,因此用了如下三个语句. find . -type f | xargs g ...
shell 查找字符串中字符出现的位置
#!/bin/bash a="The cat sat on the mat" test="cat" awk -v a="$a" -v b=& ...
Linux Shell编程第3章——正则表达式
目录 正则表达式基础 正则表达式的扩展 通配 grep命令 正则表达式基础 Linux Shell以字符串作为表达式向系统传达意思.元字符(Metacharacters)是用来阐述字符表达式意义的字符 ...
随机推荐
hdu 3632 A Captivating Match(区间dp)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3632 题意:n个人进行比赛,每个人有一个价值a[i],最后冠军只有一个,只能相邻两个人进行 ...
Select Option
jQuery获取Select元素,并选择的Text和Value: 1. $("#select_id").change(function(){//code...}); //为Sele ...
使用python+pychram进行API测试(接口测试)初级STEP 1
花了一天时间安装了解了下最基本的python+pychram进行API测试,下面这个可以指导自己以后入门:基本的开发级别还需要学习 1.python下载地址:https://www.python.or ...
oracle TIMESTAMP日期相减
select extract(day from inter) * 24 * 60 * 60 + extract(hour from inter) * 60 * 60 + extract(minute ...
Algorithm: cartesian tree
http://baike.baidu.com/link?url=XUt5fXQ-jtFBM0UdKiGA41_NWFvdFSYwVsy4SVvCRRuEBvNkLfT9TgOtzsXvaOT9nuq_ ...
查看Linux系统的版本以及位数
1.查看版本 http://jingyan.baidu.com/article/215817f7e360bd1edb142362.html[root@localhost usr]# lsb_relea ...
关于springmvc时request的getReader()和getInputStream()只能调用一次的解决办法
最近准备在原有的SSM项目的基础上添加完善的日志分析,由于是APP的后台系统,之前在规划APP的时候,并没有在APP上做埋点的处理,而如果想要进行埋点处理的话,对于未能新升级的APP用户来说,就是去了 ...
PlainElastic.Net
PlainElastic.Net PlainElastic.Net The really plain Elastic Search .Net client. Idea Installation How ...
汇编 gdb调试
as -g --32 -o hello.o hello.s ld -m elf_i386 -o hello hello.o gdb hello
instance of的java用法
http://blog.csdn.net/liranke/article/details/5574791