Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ls command format

Status
Not open for further replies.

buxtonicer1

Programmer
Sep 20, 2006
82
GB
I've got a list of files on NT. I've got mkstoolkit which gives me access to lots of UNIX commands. I'd like to list filenames with just their name and size or checksum. But I'd like the output in such a way as that I can copy and paste it into an Excel spreadsheet. Any ideas ?
 
Hi

Some possibilities :
Code:
[gray]# sure there are no whitespace characters in the nfile names[/gray]
ls -l | awk '{print$5"\t",$8}'

[gray]# better way[/gray]
ls -l | awk '{$1=$2=$3=$4=$6=$7="";sub(/^ +/,"")}1'

[gray]# or[/gray]
ls -l | awk '{printf"%s\t",$5;for(i=8;i<=NF;i++)printf"%s%s",$i,(i<NF)?" ":"\n"}'

[gray]# recursive in subdirectories[/gray]
find . -printf '%f\t%s\n'

[gray]# checksum if there are a few files[/gray]
md5sum *

[gray]# for many files[/gray]
ls | xargs md5sum
I never heard about MKS Toolkit, but if it provides UNIX compatible environment, the above commands will work.

Feherke.
 
I guess what I need is a command that
prints the file details column by column with one tab difference so I can put them into a spreadsheet. Not sure if the above commands do that. I'm new to awk so will investigate more.

MKS toolkit is an NT app that gives you unix type commands on NT
 
Hi

All of the above approaches which contains the [tt]\t[/tt] will use a horizontal tab character as field separator.

Additionally one more combination :
Code:
[gray]# filename[small][i]<tab>[/i][/small]size[small][i]<tab>[/i][/small]checksum[/gray]
find . -printf '%f\t%s\t' -exec bash -c 'md5sum < {}' \;

[gray]# similar as above but without the trailing dash ( - ) after the checksum[/gray]
find . -printf '%f\t%s\t' -exec bash -c 'md5sum < {} | cut -f1 -d" "' \;
Tested with GNU [tt]find[/tt]. Certainly works on CygWin, not sure about MKS Toolkit.

Feherke.
 
Maybe thats it. I might check it in a UNIX environment as well. Useful commands to know though.
 
buxtonicer1,

Another option would be to setup the output as a CSV file. By default Excel understand this file format and will give you the columnar format you are look for as long as the comma is not necessary to your data format I know this will work as well.

Cheers,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top