需要帮助来实现文件查看脚本 [英] Need help achieve a file viewing script

查看:57
本文介绍了需要帮助来实现文件查看脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来查看bash脚本文件.

我有30分钟都可以使用的文件,我会在按日期命名的文件夹中自动进行调整例如:

 /Data/运算符/20160515/EXPLOIT//数据/运算符/20160516/EXPLOIT//数据/运算符/20160517/EXPLOIT//数据/运算符/20160518/PROD//数据/运算符/20160518/PROD//数据/运算符/20160518/PROD/ 

每个文件夹都包含"datehour-toto.tz"格式的一天中的文件,我希望以脚本类型(例如"send.sh 201605151530 201605171300")在ls示例中自动列出这两个日期之间的所有文件?/p>

我不知道从哪里开始,因为这使我很难达到目标?因为它需要2个日期和时间中的每个文件检查器

我发现可能是一个好的开始,但是我不知道如何告诉EXPLOIT子目录

  directory ="data/"查找$ {directory} -type f |awk -vSTART = $ 1 -vSTOP = $ 2'{t = substr($ 0,length('$ {directory}'")+ 10,12)}吨START&&t <停止 {打印}'./send.sh 201508190810 201508190900数据/20150819/201508190821-toto.tz数据/20150819/201508190823-toto.tz数据/20150819/201508190820-toto.tz数据/20150819/201508190822-toto.tz 

如果有人可以帮助我,我的英语不会说很多.

解决方案

这是一种更快的方法:

 查找数据-maxdepth 2 -type d -name EXPLOIT |awk -v start = $ 1 -v end = $ 3 -F/'$ 2> =开始&&$ 2< = end'|xargs -I {}查找"{}"-类型f |awk -v start = $ 1 $ 2 -v end = $ 3 $ 4 -F/'$ 4> =开始&&$ 4< = end' 

用法:

 <代码> ./send.sh 20160515 1530 20160517 1300 

还有一种在命令行而不是在脚本中执行此操作的快速简便的方法:

 查找数据/2016051 */EXPLOIT -type f |awk -F/'$ 4> = 201605151530&&$ 4< = 201605171300' 

这是如何工作的?

 查找数据/2016051 */EXPLOIT 

在名为2016051 *的目录中找到名为EXPLOIT的目录,因此:20160510-20160519.它通过不考虑其他目录来节省时间.这种方式甚至更快:

 查找数据/2016051 [567]/EXPLOIT 

它位于目录20160515、20160516、20160517内.

如果要搜索20160529-20160601,请尝试:

 查找数据/20160 */EXPLOIT 

或者更快:

 查找数据/20160 [56] */EXPLOIT 

I need help to make a bash script file viewing.

I I have files that I get all the 30 minute, I automatic ranges in folders named by date ex:

/Data/ operator/20160515/EXPLOIT/
/Data/ operator/20160516/EXPLOIT/
/Data/ operator/20160517/EXPLOIT/

/Data/operator/20160518/PROD/
/Data/operator/20160518/PROD/
/Data/operator/20160518/PROD/

each folder contains files of a day in the format "datehour-toto.tz" I would like in a script type eg "send.sh 201605151530 201605171300" automatically list all the files between these two dates in a ls example ?

I do not know where to start because it made me tough the air achieve? because it takes every file checker in the 2 dates and times

I found something that might be a good start, but I do not know how to tell the EXPLOIT subdirectory

directory="data/"
find ${directory} -type f | awk -vSTART=$1 -vSTOP=$2 '
{
t = substr($0, length("'${directory}'")+10, 12)
}
t > START && t < STOP {
print
}'


./send.sh 201508190810 201508190900
 data/20150819/201508190821-toto.tz
 data/20150819/201508190823-toto.tz
 data/20150819/201508190820-toto.tz
 data/20150819/201508190822-toto.tz

if anyone could help me , I do not speak much English .

解决方案

here is a faster way:

find data -maxdepth 2 -type d -name EXPLOIT |
  awk -v start=$1 -v end=$3 -F/ '$2>=start && $2<=end' |
  xargs -I{} find "{}" -type f |
  awk -v start=$1$2 -v end=$3$4 -F/ '$4>=start && $4<=end'

usage:

./send.sh 20160515 1530 20160517 1300

there is also a fast and easy way to do this on the command line instead of in a script:

find data/2016051*/EXPLOIT -type f | awk -F/ '$4>=201605151530 && $4<=201605171300'

how does this work?

find data/2016051*/EXPLOIT

finds directories named EXPLOIT inside of directories named 2016051*, so: 20160510 - 20160519. it saves time by not considering other ones. this way is even faster:

find data/2016051[567]/EXPLOIT

it finds inside of directories 20160515, 20160516, 20160517.

if you wanted to search from 20160529 - 20160601, try:

find data/20160*/EXPLOIT

or, faster:

find data/20160[56]*/EXPLOIT

这篇关于需要帮助来实现文件查看脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆