Answer» Hi all,
I have a requirement where I need to capture the file names, check the date in the file names and proceed and load the data from all the FILES only if all the file names have the same date in them. Lets say, I have few files, X_US_20130420.CSV, X_CA_20130420.CSV,X_PH_20130420.CSV,X_NS_20130420.CSV. I need to check if all the files have the same date (20130420 here) and then use that date as a PARAMETER in my next job. Please help.
Thanks in advance, DhruuvI know I'm necroposting here, but no one has answered and I think I can help you here: Since it looks like you have the same format of file every time in that the extra stuff is always the same number of chars, what you're going to want to do is remove the beginning and end of the file, leaving you with only the numbers left. You could EITHER do this in Linux shell script, or you could use Java or something to take an argument and take care of it for you...which I may or may not have done because I was bored >< You can run it using "java Format " and that will print out the date for you, and you should be able to do that from within a Linux shell script. Of course, you'll need to compile it first...here's the source code: Code: [Select]public class Format {
public static void main(STRING[] args) { if(args.length == 0) { System.out.println("Usage: java Format <file>"); return; } System.out.println(args[0].substring(5,13)); }
} You're going to want to take that code and copy it into Notepad or gedit or something and save it as Format.java. You'll then want to go to the commandline and run "javac Format.java", or it may just be "javac Format" without the ".java" part. You may need to install a JDK to use javac if you haven't already.
If you want to do it in Linux shell, you'll want to use head and tail and LOOK up the "-k" option for both, or just call "head --help" on the commandline. Good luck!
|