• 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: Counting Identical lines in a file with BBEdit & Grep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Counting Identical lines in a file with BBEdit & Grep


  • Subject: Re: Counting Identical lines in a file with BBEdit & Grep
  • From: John Delacour <email@hidden>
  • Date: Sun, 27 Jul 2003 20:10:12 +0100
  • Mac-eudora-version: 6.0a28

At 11:02 am -0700 27/7/03, Marconi wrote:

Given a text file containing multiple instances of about a dozen different lines, is it possible, in BBEdit, to count the number of times each unique line appears?

There's no need to use BBedit or any editor or any pattern matching. Just read the lines from the file as keys of a hash (%h) and increment the value each time you find the string. Here's an example which creates the file and then does just that:

set _paras to paragraphs of "123456789
abcdefgh
123456789
opqrstuv
123456789
abcdefgh
dsltcpip
abcdefgh
123456789
abcdefgh
123456789
opqrstuv
abcdefgh
123456789
opqrstuv
opqrstuv"
(* CREATE SAMPLE FILE *)
set lf to ASCII character 10
set fU to "/tmp/f"
set f to fU as POSIX file
open for access f with write permission
set eof f to 0
repeat with _line in _paras
write _line & lf to f
end repeat
close access f
(* *)
do shell script "perl -e ' $f = qq~/tmp/f~; open F, $f;
for (<F>) { chomp ; $h{$_} += 1 }
for (sort keys %h) { print qq~$_ - $h{$_}\\n~ }'"
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Counting Identical lines in a file with BBEdit & Grep (From: Marconi <email@hidden>)

  • Prev by Date: Suggestions? Entourage Email Address in message contents
  • Next by Date: Re: Suggestions? Entourage Email Address in message contents
  • Previous by thread: Counting Identical lines in a file with BBEdit & Grep
  • Next by thread: Re: Counting Identical lines in a file with BBEdit & Grep
  • Index(es):
    • Date
    • Thread