- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would like to rename multiple file extensions from EU to txt using the below code result but I dont get the desired results.
Please note that I am using the UNIX environment.
DATA _NULL_;
X 'rename /EIP/Data/Lev1/Data/FBM/.*EU /EIP/Data/Lev1/Data/FBM/*.txt';
RUN;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A couple of items to fix this ...
First, note that SAS does not require a DATA step in order to run the X command. You only need one line of code.
Second, note that you need a legitimate Unix command. There is no "rename" command in Unix. There is both "mv" and (I believe) "rnm". So get your command working in Unix first, without using SAS. Then it should be straightforward to convert it to a SAS X command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Also you may want to double check the location of the wildcard character * in the source part of the command
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Do you really need to change the extension? What will having the new extention get you that EU cannot provide.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I did not know that you can an EU file using SAS, just tried it and it worked.
Really appreciated... But I would also like to know how to rename multiple files that resides in the same UNIX directory.
I used the below piece of code in windows environment and it worked..
filename ren pipe "dir C:\Users\Desktop\FBM\FILES\NEW\*.EU /b /s";
/*To get the corresponding new file names*/
data ren;
infile ren;
input old : $250.;
new=tranwrd(old,".EU",'.TXT');
run;
/*To rename them all*/
data _null_;
set ren;
rc=rename(old, new, 'file');
put rc;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think a similar program using SAS RENAME function would work in UNIX just as well as Windows.
I was fiddling with this one line bash script. It does not exectue 'MV' just shows the command with ECHO. It's really the same as your SAS program only different language. I think most folk would do some kind of GREP thing but I'm not good with that.
-
for file in x*.xml; do echo "Process: $file"; x=`basename $file .xml`; echo "mv $file ${x}.txt"; done;
- For each file that matches the pattern x*.xml
- print the file name
- assign x the filename with .xml removed
- print the mv command
>for file in x*.xml; do echo "Process: $file"; x=`basename $file .xml`; echo "mv $file ${x}.txt"; done; Process: xmltest.xml mv xmltest.xml xmltest.txt Process: xp1.xml mv xp1.xml xp1.txt Process: xp2.xml mv xp2.xml xp2.txt
Assumes UNIX shell is BASH