Re: the use of "cut -f8 -d" and "find -name"
cut -f8 -d "/"
That gives you the eight field in a string delimited by "/". So on a string like "a/b/c/d/e/f/g/h/i/j" it will give you "h"
find /coe/informatica/v712_OMJ/AONE/SrcFiles/Archive -name *AccessOne_DF_BIFs.txt
The -name option specifies the pattern to match for. The whole command above will recursively search for all files within the Archive directory that ends with "AccessOne_DF_BIFs.txt"
This is what the whole command does:
- find /coe/informatica/v712_OMJ/AONE/SrcFiles/Archive -name *AccessOne_DF_BIFs.txt - recursively look for all "AccessOne_DF_BIFs.txt" files within the Archive directory
- cut -f8 -d "/" - From the output of the previous command, extract the eight field delimitted by "/"
- cut -c 1-12 - Extract only the first 12 characters
- > /coe/informatica/v712_OMJ/AONE/TgtFiles/ExtendedAOneWeeklySource/WeeklyDeltaFileLoadIDList.dat - Write out the results into the WeeklyDeltaFileLoadIDList.dat file
Re: Windows replacement
My DOS-fu and PowerShell-fu is severely lacking, so I can't help you there. However, you can use the same commands on windows if you used Cygwin or MSYS. Do note however that the paths to your files will be different when accessed from within Cygwin/MSYS. If you wish to use windows directory structures (e.g. C:\my\windblows\directory), then you may have a better chance with MSYS.
~ Update ~
re: equivalent command in DOS
Had a go during coffee break and this seems to work for me.
DOS-fu:
@echo off
:: Source directory
set SRCDIR="C:\coe\informatica\v712_OMJ\AONE\SrcFiles\Archive"
:: Pattern to match
set TARGET="*AccessOne_DF_BIFs.txt"
:: Set output file
set OUTFILE="C:\coe\informatica\v712_OMJ\AONE\TgtFiles\ExtendedAOneWeeklySource\WeeklyDeltaFileLoadIDList.dat"
:: Store current working directory so we can send user back
set PWD=%cd%
:: Move to source directory so our "dir" command will work
cd %SRCDIR%
:: Reset previous output file
del %OUTFILE%
:: This is where the script actually starts
FOR /F "usebackq tokens=8 delims=\" %%a IN (`dir %TARGET% /s/b`) DO (
set X=%%a
echo %X:~0,13%
) >> %OUTFILE%
:: Send user back to where he/she was
cd %PWD%
Not quite the one-liner that you can get with Unix 'find' and 'cut', but it gets the same job done (I hope) using only built-in DOS directives.
The FOR loop is what does the job. The rest are mostly there to make the script more readable.
Note that "echo %X:~0,13%" is not a typo and ought to be equivalent to "cut -c 1-12".
I bet there are cleaner and more elegant ways to do it. This was my first attempt at DOS-fu so be nice.
Sources: