Unix/SAS 上的文件修改日期 [英] File modification date on Unix/SAS

查看:22
本文介绍了Unix/SAS 上的文件修改日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是 DATA SET 步骤的伪装.我在以通用前缀开头的目录中获取文件.

Below is the guise of the DATA SET step. I got files in a directory which start with a common prefix.

为了这个调试程序,假设前缀是'test'.

For the sake of this debugging program, let's say the prefix is 'test'.

所以我们得到了 test_abc.txt、test_123.txt 等文件.

So we got files like test_abc.txt, test_123.txt and so on.

我们要做的是提取每个文件的最后修改时间.由于我是在Unix系统下,所以我使用下面的foo pipe 'ls -o -g --full-time ...'"来获取我们感兴趣的时间.

What we want to do is to extract the last modified time of each file. Since I am under Unix system, I use the following "foo pipe 'ls -o -g --full-time ...'" to get the time which we are interested in.

在work.tempo中,我希望得到一个包含文件名(vname)列表和相应修改日期(mod_datec)的表.

In work.tempo, I wish to get a table with a list of filename(vname) and the corresponding modification date (mod_datec).

Voilà le souci,je vous remercie!

Voilà le souci, je vous remercie!

 %macro universe(directory, countryname, prefix);

  data work.tempo;
  length vname $256.;
  rc   = dopen(&directory);
  vmax = dnum(rc);

  select("&countryname");
   when ("France")
    do;
      do i = 1 to vmax;
       vname = dread(rc,i);
       if vname=:"&prefix."
        then do;

         filename foo pipe "ls -g -o --full-time ~/&prefix.*";

         data _null_;
         infile foo;
         input @15 mod_date $11.;
         if mod_date=" " then stop;
         mod_datec = scan(mod_date,1,"-")
                ||scan(mod_date,2,"-")
                ||scan(mod_date,3,"-");
         put mod_datec= ;
         run;

           /*I want to output mod_datec to work.tempo from here*/

        end;
      end;
    end;



  otherwise;        
  end;

  rc = dclose(rc);
  run;

 %mend;

 %universe(Earth, France, test);    

推荐答案

我已经复制了 OP 的答案(错误地嵌入了问题中):

I've copied the OP's answer (which is incorrectly embedded in the question):

我已经解决了这个问题.下面是代码

I've resolved this one. Below is the code

%macro universe();                          
    filename 
     foo pipe 
        "ls -g -o -G -l --full-time test* | awk '{print $4, $5, $7}'";

    data mod_date (keep = vname vdate);
    infile foo;
    input @1  mod_date $10.
          @12 heures   $8. 
          @92 vname    $18.;

        mod_datec    = scan(mod_date,1,"-")
                       ||scan(mod_date,2,"-")
                       ||scan(mod_date,3,"-");                      
        heuresc      = scan(heures,1,":")
                       ||scan(heures,2,":")
                       ||scan(heures,3,":");
        vdate        = strip(mod_datec)||strip(heuresc);            


    run;

%mend universe;
%universe();

瞧,我终于提取了文件名和相应的最后修改日期.我希望它对其他人也有用

Voilà, I finally got to extract the filename and the corresponding last modification date. I hope it'll be useful to anyone else too

这篇关于Unix/SAS 上的文件修改日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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