grep -v "Date" /path/to/listing | awk '{printf "%s \t%s\n", $5, $4}'
Main Topics
Browse All TopicsHi,
I have a listing of files in the following format (from MSDOS "dir" output):
03/15/2008 06:31 PM 25 100011.uuid
03/15/2008 06:31 PM 189,440 10001411.uuida
I would like a script to read the file to strip off the date & time columns &
reproduce a new file which only has 2 columns : filename followed by filesize.
Attached is a sample listing (the top few lines) and the desired output (bottom
few lines)
Can be a Unix Shell script or an MSDOS Batch script.
Note that the file is very huge, about 1.5Gb in size, so the script must be
able to read such a big file & not bombs out (as vi editor, MS Excel & MS Word
can't open the file)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
From Windows side.... 2 questions.
Can you re-run the dir output? If so can easily just produce name and size using a for command etc. but working on what you have from dos for completeness:
@echo off
setlocal enabledelayedexpansion
set outfile=outfile.txt
del %outfile% 2>NUL
for /f "tokens=4* delims= " %%a in (c:\filelist.txt) do set size=%%a& set size=!size:,=!&(echo !size!,%%b)>>%outfile%
You can re-arrange the final echo bit as needed. This sends size,filename at the mo. and the other bits before remove the commas in the size field.
for /f "tokens=4* delims= " %%a in (c:\filelist.txt) do (echo %%a %%b)>>%outfile%
would send it as you request specifically.
Steve
Thanks guys, the filenames do not have spaces in between, fortunately.
So these scripts (Unix & MSDOS) would not bomb out half way due to the
large input file size, right?
To clarify Dragon-it, codes, (yes, I want the filename first), so is the following codes correct :
(Note: I assume the codes below is reading filelist.txt & not reissuing "dir ..." command again, right?)
@echo off
setlocal enabledelayedexpansion
set outfile=outfile.txt
del %outfile% 2>NUL
for /f "tokens=4* delims= " %%a in (c:\filelist.txt) do set size=%%a& set size=!size:,=!&(echo %%b %%a)>>%outfile%
Or is there an MSDOS "dir/..." options that would just give me the filename & sizes
without other information (dir/b/
Correct. %%a is the first "token" on the line and %%b is the rest of the line. The "tokens=4*" bits means assign the 4th token to the variabl given (%%a) and the rest of the line (in case of spaces) to the next variable (%%b). This could have been then if there are no spaces: "tokens=4,5" or "tokens=4-5" or you could have used "tokens=1-5" and then %%a is the date, %%b the time, %%c is AM or PM, %%d is the size and %%e the filename...
Hope that doesn't confuse more!
You could do a
for /r %a in (c:\*.*) do echo %~na %~za
To get the filename and size (for /? for details) of all files in the dir (this from command line you replace each % with %% to put it in a batch file. This only works from NT4 upwards, not "proper" DOS or Windows 9x DOS so if you have a real DOS OS you can't do that, though of course if you have the drive in a newer OS you CAN.
Steve
Business Accounts
Answer for Membership
by: oheilPosted on 2009-10-12 at 05:40:10ID: 25550671
unix:
awk '{print $4,$5;}' your_file_name
or if you want to create the result in a new file:
awk '{print $4,$5;}' your_file_name > your_new_file
If you have spaces in the file names (last column in your file) this would be a problem with awk.
It would be best, if the columns would be tab separated. In this case the awk command looks like:
awk 'BEGIN{FS="\t";}{print $4,$5;}' your_file_name
Regards,
Oli