Linux egrep和join

时间:2014-08-23 11:19:45

标签: bash join lines

我想在一行中加入两个stat(修改日期和名称)字段

 stat *|egrep  'File|Modifica'

 File: "expresso"
Modifica : 2014-07-21 19:03:53.797915876 +0200
  File: "file"
Modifica : 2014-08-17 02:19:14.116184772 +0200

我希望输出

 File: "expresso"  Modifica : 2014-07-21 19:03:53.797915876 +0200
 File: "file"      Modifica : 2014-08-17 02:19:14.116184772 +0200

我尝试了很多tr,paste,perl但没有工作。 感谢

2 个答案:

答案 0 :(得分:1)

在Linux上:

stat -c 'File: %n Modified: %y' t*

生成例如

File: t Modified: 2014-07-30 09:56:20.000000000 +0200
File: tdir Modified: 2014-08-14 23:40:21.000000000 +0200
File: test Modified: 2014-08-22 14:35:26.000000000 +0200
File: test.xml Modified: 2014-08-03 20:36:42.000000000 +0200

stat -c 'File: %n Modified: %y' t* | column -t

生成如下行:

File:  t         Modified:  2014-07-30  09:56:20.000000000  +0200
File:  tdir      Modified:  2014-08-14  23:40:21.000000000  +0200
File:  test      Modified:  2014-08-22  14:35:26.000000000  +0200
File:  test.xml  Modified:  2014-08-03  20:36:42.000000000  +0200
OS X上的

stat -f 'File: %N Modified: %t%Sm' t* |column -t

打印

File:  t         Modified:  Jul  30  09:56:20  2014
File:  tdir      Modified:  Aug  14  23:40:21  2014
File:  test      Modified:  Aug  22  14:35:26  2014
File:  test.xml  Modified:  Aug  3   20:36:42  2014

答案 1 :(得分:0)

通过pastecolumn

$ paste -d" " - - < file | column -t
File:  "expresso"  Modifica  :  2014-07-21  19:03:53.797915876  +0200
File:  "file"      Modifica  :  2014-08-17  02:19:14.116184772  +0200