我想累积一个文件夹中包含的多个文件的行大小。我编写了以下脚本:
let a=0
let num=0
for i in folder/*
do
num=`cat $i | wc -l`
a=$a+$num
done
echo $a
Run Code Online (Sandbox Code Playgroud)
我在脚本末尾得到的是 123+234+432+... 而不是加法运算的结果。
我想用正则表达式匹配某些行之间的所有内容,但不匹配开始和结束。这听起来对我来说是积极的后视和积极的前瞻
start text
bla bla
bla
end
Run Code Online (Sandbox Code Playgroud)
有多个这种块,所以我想提取所有这些块,然后对于这些块中的每一个,我想根据不同的正则表达式提取一些东西。所以它应该是这样的:
match start
then match everything until the first occurrence of end
match start
then match everything until the first occurrence of end
Run Code Online (Sandbox Code Playgroud)
等等...
所以我做了这样的事情:(?<=start).*(?=end)
这不起作用,因为我想我使用命令行 grep,它将文件视为一组行并尝试在每一行中应用正则表达式。有没有办法将文件视为整行,或者这不是一个好的解决方案,我必须使用各种命令行工具的组合,例如用 sed 提取文本,然后构建一个文件,其行包含各行的串联从初始文件?