bash字符串匹配
#!/bin/sh
foo()
{
local basedir=$1
local all_entries=`ls -c`
for entry in $all_entries
do
if test -d $entry; then
cd $entry&&foo ${basedir}/$entry;cd - >/dev/null
else
if [[
$entry =~ .+\.(cpp|cc|h|hpp) ]]; then #
看这里
#echo $basedir/$entry
source_files="$source_files $basedir/$entry"
fi
fi
done
}
foo .
echo $source_files
An additional binary operator, =~,
is available, with the same precedence as == and !=. When it is used, the string to the right of the operator is considered an extended regular expression and matched accordingly (as in regex(3)). The return value is 0 if the string matches the pattern,
and 1 otherwise. If the regular expression is syntactically incorrect, the conditional expression's return value is 2.
emacs和posix-basic不支持()特性
find . -path ./task -prune -o -print | awk '/.cpp$|.h$/ { printf("%s ",$0); }'
语议:
if -path ./task; then
-prune
else
-print
fi
-o是or的意思
bash字符串匹配的更多相关文章
- leetcode笔记 动态规划在字符串匹配中的应用
目录 leetcode笔记 动态规划在字符串匹配中的应用 0 参考文献 1. [10. Regular Expression Matching] 1.1 题目 1.2 思路 && 解题 ...
- 字符串匹配的KMP算法
~~~摘录 来源:阮一峰~~~ 字符串匹配是计算机的基本任务之一. 举例来说,有一个字符串”BBC ABCDAB ABCDABCDABDE”,我想知道,里面是否包含另一个字符串”ABCDABD”? 许 ...
- {Reship}{KMP字符串匹配}
关于KMP字符串匹配的介绍和归纳,作者的思路非常清晰,推荐看一下 http://blog.csdn.net/v_july_v/article/details/7041827
- 字符串匹配(hash算法)
hash函数对大家来说不陌生吧 ? 而这次我们就用hash函数来实现字符串匹配. 首先我们会想一下二进制数. 对于任意一个二进制数,我们将它化为10进制的数的方法如下(以二进制数1101101为例): ...
- 【C++实现python字符串函数库】二:字符串匹配函数startswith与endswith
[C++实现python字符串函数库]字符串匹配函数startswith与endswith 这两个函数用于匹配字符串的开头或末尾,判断是否包含另一个字符串,它们返回bool值.startswith() ...
- sdut 2125串结构练习--字符串匹配【两种KMP算法】
串结构练习——字符串匹配 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目链接:http://acm.sdut.edu.cn/sduto ...
- C语言字符串匹配函数
C语言字符串匹配函数,保存有需要时可以用: #include <stdio.h> #include <stdlib.h> #include <string.h> # ...
- 字符串匹配--Karp-Rabin算法
主要特征 1.使用hash函数 2.预处理阶段时间复杂度O(m),常量空间 3.查找阶段时间复杂度O(mn) 4.期望运行时间:O(n+m) 本文地址:http://www.cnblogs.com/a ...
- 字符串匹配的KMP算法详解及C#实现
字符串匹配是计算机的基本任务之一. 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD" ...
随机推荐
- GetWindowRect和GetClientRect比较学习
一:关于坐标 MFC中绘图时经常涉及到坐标计算,GetWindowRect和GetClientRect这两个函数,是获取逻辑坐标系中窗口或控件(其实也是窗口)大小和坐标的常用函数了,有什么不一样的? ...
- 算法(Algorithms)第4版 练习 2.2.10
关键代码实现: private static void merge(Comparable[] input, int lo, int mid, int hi) { //copy input[lo,mid ...
- TCP/IP 协议中的编址
TCP/IP协议的互联网需要用到四个级别的地址:物理地址.逻辑地址.端口地址和特定应用地址 一.物理地址 物理地址称为链路地址,是由接点所在的局域网或广域网为该结点指定的地址. 这种地址的长度和格式随 ...
- ubuntu commands mysql
use table; //选择某个表 show tables; //展现有几个表 select * from table; //显示表内容
- 异步刷新页面的前进与后退的实现--pushState replaceState
实现目标 页面的跳转(前进后退,点击等)不重新请求页面 页面URL与页面展现内容一致(符合人们对传统网页的认识) 在不支持的浏览器下降级成传统网页的方式 使用到的API history.state 当 ...
- web项目中添加logger日志
在项目中添加log4j.xml文件 log4j.xml文件 <?xml version="1.0" encoding="UTF-8" ?><! ...
- Hibernate学习---第十三节:hibernate过滤器和拦截器的实现
一.hibernate 过滤器 1.在持久化映射文件中配置过滤器,代码如下: <?xml version="1.0"?> <!DOCTYPE hibernate- ...
- BEC listen and translation exercise 33
In fact, if it is a really hot day, like the sort of weather we had last summer, you are advised to ...
- codeforces 655A A. Amity Assessment(水题)
题目链接: A. Amity Assessment time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- CI中site_url和base_url的区别
你若使用site_url("test/php/1");则实际url为 http://domain.com/index.php/test/php/1 若使用base_url(&quo ...