Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell ';{读取txt文件并过滤带有日期<;date、>;date和介于日期之间的记录}';_Shell_Awk_Sed - Fatal编程技术网

Shell ';{读取txt文件并过滤带有日期<;date、>;date和介于日期之间的记录}';

Shell ';{读取txt文件并过滤带有日期<;date、>;date和介于日期之间的记录}';,shell,awk,sed,Shell,Awk,Sed,sample.txt -rw-r--r-- 1 atom atom 0 Jul 5 14:30 file4.txt -rw-r--r-- 1 atom atom 0 Jul 6 14:31 file6.txt -rw-r--r-- 1 atom atom 0 Jul 7 12:15 file9.txt -rw-r--r-- 1 atom atom 0 Jul 8 12:15 file8.txt -rw-r--

sample.txt

-rw-r--r--    1 atom atom        0 Jul  5 14:30 file4.txt
-rw-r--r--    1 atom atom        0 Jul  6 14:31 file6.txt
-rw-r--r--    1 atom atom        0 Jul  7 12:15 file9.txt
-rw-r--r--    1 atom atom        0 Jul  8 12:15 file8.txt
-rw-r--r--    1 atom atom        0 Jul  9 14:03 file7.txt
-rw-r--r--    1 atom atom        0 Jul 10 14:03 file66.txt
-rw-r--r--    1 atom atom        0 Jul 11 11:41 file5.txt
-rw-r--r--    1 atom atom        0 Jul 12 11:42 file4.txt
drwxr-xr-x    2 atom atom     1024 Jul 13 09:12 file3.txt
-rw-r--r--    1 atom atom     4401 Jul 14 09:46 file2.txt
-rw-r--r--    1 atom atom     4401 Jul 14 09:46 file1.txt
我想根据日期确定记录

例如,如果我想确定过去8天的文件,则表示从7月14日到7月7日

预期产出:

-rw-r--r--    1 atom atom        0 Jul  7 12:15 file9.txt
-rw-r--r--    1 atom atom        0 Jul  8 12:15 file8.txt
-rw-r--r--    1 atom atom        0 Jul  9 14:03 file7.txt
-rw-r--r--    1 atom atom        0 Jul 10 14:03 file66.txt
-rw-r--r--    1 atom atom        0 Jul 11 11:41 file5.txt
-rw-r--r--    1 atom atom        0 Jul 12 11:42 file4.txt
drwxr-xr-x    2 atom atom     1024 Jul 13 09:12 file3.txt
-rw-r--r--    1 atom atom     4401 Jul 14 09:46 file2.txt
-rw-r--r--    1 atom atom     4401 Jul 14 09:46 file1.txt 
ls-l
用于长输出

然后
awk
将找到包含
Jul
和(&&&)第七个参数($7)的行需要大于或等于8


0+
用于将字母数字转换为数字,因为将字符串与整数进行比较是没有用的。

为什么你甚至不尝试使你的问题更具可读性?请你现在检查一下,在你的问题中选择适当的文本后,你能使用“{}”吗?我们不会为你做全部的家庭作业,只是帮你而已。向我们展示您的代码,并关注您遇到的特定问题。告诉我们您已经了解的情况,您正在努力解决的问题。例如,如果
sample.txt
包含
ls
的输出(看起来是这样),并且您正在尝试解析它,那么如果一个文件有6月份的时间戳,但名为
Julius.txt
,则会失败。还要注意常见的警告:。谢谢you@Luuk,@john,@Ed mort以通用方式与awk进行了比较,另一个问题是它不适用于6个月的旧日期列表
awk-vDate=
date+'%b%e''''-vDate2=
date+'%b%e'-d'-7天'
'{if($6'$7>Date2&$6'$7ls-l--full-time,这样可以更容易地检查日期。
ls -l  | awk '/Jul/ && 0+$7>=8'