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

Counting Identical lines in a file with BBEdit & Grep


  • Subject: Counting Identical lines in a file with BBEdit & Grep
  • From: Marconi <email@hidden>
  • Date: Sun, 27 Jul 2003 11:02:48 -0700

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?

Given:

123456789
abcdefgh
123456789
opqrstuv
123456789
abcdefgh
dsltcpip
abcdefgh
123456789
abcdefgh
123456789
opqrstuv
abcdefgh
123456789
opqrstuv
opqrstuv

can BBEdit be scripted to distill it to:

6: 123456789
5: abcdefgh
4: opqrstuv
1: dsltcpip

where the number at each line start is the count...

Would it be more doable or easier if the file were to be sorted first so that the input was:
123456789
123456789
123456789
123456789
123456789
123456789
abcdefgh
abcdefgh
abcdefgh
abcdefgh
abcdefgh
dsltcpip
opqrstuv
opqrstuv
opqrstuv
opqrstuv


I have the following script line which removes all but 1 instance of each unique line in a SORTED list. Is there a way to get grep to keep track of how many duplicates it removes for each unique line and thus give me a count?

(If the below line looks like strange grep, it's because some characters need to be escaped for both AppleScript and Grep.)


replace "^(.*\\r)\\1+" using "\\1" searching in text 1 of text window 1 options {search mode:grep, starting at top:true, wrap around:false, reverse:false, case sensitive:false, match words:false, extend selection:false}





--

"A man who believes in nothing will fall for anything." -- Malcolm X
_______________________________________________
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.

  • Follow-Ups:
    • Re: Counting Identical lines in a file with BBEdit & Grep
      • From: John Delacour <email@hidden>
  • Prev by Date: Re: OT: of X, Unix, Linux and Microsoft
  • Next by Date: Re: RA connection was Re : no subject
  • Previous by thread: do JavaScript with Safari
  • Next by thread: Re: Counting Identical lines in a file with BBEdit & Grep
  • Index(es):
    • Date
    • Thread