Last active
June 3, 2021 10:25
-
-
Save rudvfaden/5c70acb5f3a84fe226f78cf65d41f887 to your computer and use it in GitHub Desktop.
Finds filenames in a given folder using linux pipe for faster execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%let target_folder=/sasfolders/data/IBprojekt/HRSTAT/produktion/programmer/krl/; | |
*makes it indifferent wheter or not you add / to the end of the string; | |
%let target_folder=%tslit(%sysfunc(tranwrd(%sysfunc(cats(&target_folder,/)),//,/))); | |
filename pipedir PIPE | |
"ls -la --time-style=full-iso &target_folder.*.* | grep '^-'" encoding='utf-8'; | |
DATA _sm_filenames; | |
length filsti $1000 filnavn $100 navn $100 bytes 6. filDato 8.; | |
infile pipedir TRUNCOVER LRECL=5000; | |
input line $char1000.; | |
*Size; | |
reBytes=prxparse('/(\d+)\s+\d{4}/'); | |
if prxmatch(reBytes, line) then | |
do; | |
Bytes=prxposn(reBytes, 1, line); | |
end; | |
*Fil navn; | |
reFilnavn=prxparse('/([\w\dÆØÅæøå\s_\\.\-\(\):]+$)/'); | |
if prxmatch(reFilnavn, line) then | |
do; | |
filnavn=prxposn(reFilnavn, 1, line); | |
end; | |
*Fil navn uden extension; | |
reNavn=prxparse('/(.+)\..+$/'); | |
if prxmatch(reNavn, filnavn) then | |
do; | |
Navn=prxposn(reNavn, 1, filnavn); | |
end; | |
*Fil dato; | |
reFilDato=prxparse('/(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})/'); | |
if prxmatch(reFilDato, line) then | |
do; | |
filDato=input(prxposn(reFilDato, 1, line), YMDDTTM.); | |
end; | |
filsti=cats(&target_folder, filnavn); | |
format filDato datetime20.; | |
drop reFilDato reNavn reBytes reFilnavn line; | |
run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment