如何打印匹配grep模式的文件的文件细节 [英] How to print file details of files matching grep pattern

查看:127
本文介绍了如何打印匹配grep模式的文件的文件细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印文件的详细信息以及grep输出,但无法这样做。例如,对于命令

  grep 3456 A.txt 

我得到输出

  A.txt 

code>

但希望输出

  -rw-rw-r-- 1 tarun tarun 41356911 Aug 25 01:31 A.txt 

我尝试了以下方法但没有成功:


  1. grep 34567 A.txt | xargs ls -tlr


  2. grep 34567 A.txt |而读线;做回声$行|日期%s。%N;完成


  3. grep -Hr 34567 A.txt | awk -F:'{stat -c%z$ 1 | getline r; print r:$ 0'


  4. grep 34567 A.txt | awk -F:'{date -r \$ 1\+ \%F%R \| getline d; print d,$ 0}'



解决方案

  grep -Zl 3456 * | xargs -0 ls -l 

使用GNU grep。这些选项包括:


  • grep -Z xargs -0 :用NULL字节而不是空格分隔输出名称。这样你就可以处理包含空格的文件名。

  • grep -l <​​/ code>:仅打印匹配的文件名
  • ls -l <​​/ code>:标准 ls 长输出,这似乎就是您要求的。



测试最新的cygwin。


I want to print file details along with grep output but unable to do so. E.g., for the command

grep 3456 A.txt

I get the output

A.txt

but would like the output

-rw-rw-r-- 1 tarun tarun   41356911 Aug 25 01:31 A.txt

I tried the following without success:

  1. grep 34567 A.txt | xargs ls -tlr

  2. grep 34567 A.txt | while read line ; do echo "$line" | date %s.%N ; done

  3. grep -Hr 34567 A.txt | awk -F: '{"stat -c %z "$1 | getline r; print r": "$0 }'

  4. grep 34567 A.txt | awk -F: '{"date -r \""$1"\" +\"%F %R\"" | getline d; print d,$0}'

解决方案

grep -Zl 3456 * | xargs -0 ls -l

with GNU grep. The options are:

  • grep -Z and xargs -0: separate output names by a NULL byte instead of by whitespace. This way you can handle filenames that include spaces.
  • grep -l: print only the filenames that match
  • ls -l: Standard ls long output, which appears to be what you are asking for.

Tested on latest cygwin.

这篇关于如何打印匹配grep模式的文件的文件细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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