Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
find /coe/informatica/v712_OMJ/AONE/SrcFiles/Archive -name *AccessOne_DF_BIFs.txt|cut -f8 -d "/"|cut -c 1-12 > /coe/informatica/v712_OMJ/AONE/TgtFiles/ExtendedAOneWeeklySource/WeeklyDeltaFileLoadIDList.dat

please let me know the use of

cut -f8 -d and -name *AccessOne_DF_BIFs.txt //this is a file name in unix box
share|improve this question

migrated from stackoverflow.com Aug 11 '09 at 12:47

This question came from our site for professional and enthusiast programmers.

1  
There is no DOS! cmd.exe IS NOT DOS and hasn't been for ages! –  Joachim Sauer Aug 11 '09 at 12:36

6 Answers 6

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:

share|improve this answer
    
thanks buddy keep in touch...very useful stuff –  Irveen Aug 11 '09 at 10:40
1  
Minor nitpick: This can't work in DOS. It's specific to the Windows NT command prompt (cmd.exe). –  Joey Aug 11 '09 at 14:16

Can you install one of the unix-alike packages such as Cygwin?

Or maybe install a scripting language such as Perl?

Does that command of yours actually work? Maybe missing a -print from the find.

 find -name  xxx

look for the specified file name

 cut -f 8 -d "/"

split up into fields delimited by /, take the 8th one

Such things are not so smooth in raw Windows command line, hence the recommendation to install a nicer scripting environment.

share|improve this answer
3  
Windows is unusable without cygwin. How can someone survive with the powerful shell-tools. I personally didn't switched to Linux for years (I did it after XP), but since long time I used cygwin, very important tool. The link is cygwin.com –  Mnementh Aug 11 '09 at 7:50

To substitute cut type in DOS command "help for"

look at syntax:

FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k

instead (myfile.txt) specify *AccessOne_DF_BIFs.txt

to make it recursive use loop

share|improve this answer

You can find a port of common Unix utilities here on SourceForge (including find and cut).

There is not out-of-the-box way to do this on Windows that I know of.

share|improve this answer

for ports of *nix tools to windows, use the ones from GNU

share|improve this answer

I don't know about these particular commands but this is my reference for commands : http://ss64.com/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.