• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AS or Unix tools for turning find result into a nice consistent tab separated text file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AS or Unix tools for turning find result into a nice consistent tab separated text file?


  • Subject: Re: AS or Unix tools for turning find result into a nice consistent tab separated text file?
  • From: Christopher Nebel <email@hidden>
  • Date: Mon, 12 Jun 2006 20:01:32 -0700

On Jun 10, 2006, at 2:53 AM, Richard Rönnbäck wrote:

I am trying to find the fastest possible way of getting information for specific file types and turn it into a tab separated text file for import to a database. After spending tens of hours or so banging my head against regular expression etc. I am only a little bit closer and nowhere near a full solution. Before I jump into looping and treating each line with AppleScript (the find result may be up to 100 000 lines long ) I would greatly appreciate some input and good advice.

The text file I need must contain:

* file path
* Year of modification date as YYYY
* Month of modification date as  MM (numbers)
* Day of modification date as  DD (numbers)
* Time of modification date as  HH:HH (24 hour format)
* File size in bytes
* File inode number

Seeing as how you want the inode number (why escapes me, but never mind that) and will therefore have to consult some sort of non-core- AppleScript tool anyway, your best bet is probably to stick with shell to generate this list.


find(1)'s "-ls" primary is handy, but lacks any sort of control. What you need is to have find(1) just find the files, and then hand them to another command. Given all the wackiness that can occur in Mac OS file names, "-print0" paired with xargs(1) "-0" can be very helpful here. stat(1) will *almost* give you what you want, but it doesn't allow any control over the date formatting. You could either bludgeon stat(1)'s output yourself, or you could use Perl to generate exactly what you want:

find ... | \
perl -ln0e ' \
use POSIX qw(strftime); \
@info = stat($_); $inode = $info[1]; $size = $info[7]; $mtime = $info[9];
$t = POSIX::strftime("%Y\t%m\t%d\t%k:%M", gmtime($mtime)); \
print "$_\t$t\t$siz\t$i";'


The business end(s) are stat to get all the file information, and strftime to get the bits of the modification date the way you want them.


--Chris Nebel AppleScript Engineering

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: AS or Unix tools for turning find result into a nice consistent tab separated text file?
      • From: Richard Rönnbäck <email@hidden>
References: 
 >AS or Unix tools for turning find result into a nice consistent tab separated text file? (From: Richard Rönnbäck <email@hidden>)

  • Prev by Date: iCal and detached events
  • Next by Date: Re: AS or Unix tools for turning find result into a nice consistent tab separated text file?
  • Previous by thread: Re: AS or Unix tools for turning find result into a nice consistent tab separated text file?
  • Next by thread: Re: AS or Unix tools for turning find result into a nice consistent tab separated text file?
  • Index(es):
    • Date
    • Thread