Skip navigation

Determine the number of records in a file

314 Views 5 Replies Latest reply: May 12, 2012 9:51 AM by Frinton Fogey RSS
Frinton Fogey Calculating status...
Currently Being Moderated
May 12, 2012 7:02 AM

I want to analyse record types from a large input file and so far have managed to extract different groups and created the relevant files. All I want to do now is count the number of records in each file so I can produce a report showing the different types but cannot figure out how to do this, I know it will be simple but I cannot get any command to accomplish this, help please!

iMac, Mac OS X (10.7.1)
  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    May 12, 2012 7:06 AM (in response to Frinton Fogey)

    'Records in a file' is not specific enough for us to answer.  what kind of file are you talking about? what kind of records?  what's the tpical structure of a record?

  • Jeffrey Jones2 Level 6 Level 6 (8,425 points)
    Currently Being Moderated
    May 12, 2012 9:10 AM (in response to Frinton Fogey)

    What do you mean by "records"? Do you mean "lines of text"? In that case, wc:

     

    wc -l file.txt

  • twtwtw Level 5 Level 5 (4,580 points)
    Currently Being Moderated
    May 12, 2012 9:35 AM (in response to Frinton Fogey)

    in applescript, there are a few ways to count patterned text.  if (as jeffrey suggests) each record is a separate line, then you can use the following:

     

    set textContents to read "/path/to/file.txt"

    count of paragraphs of textContents

     

    if records are determined by some other process (such as a special delimiting character or phrase) you can use text items (replace the @ sign with the special character or phrase):

     

    set textContents to read "/path/to/file.txt"

    set {oldTID, my text item delimiters} to {my text item delimiters, "@"}

    set theCount to count of text items of textContents

    set my text item delimiters to oldTID

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.