Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8211053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:17:46+00:00 2026-06-07T10:17:46+00:00

Applescript: Deleting Duplicates in a text file I have a .txt file which I’ve

  • 0

Applescript: Deleting Duplicates in a text file

I have a .txt file which I’ve created, and I’m trying to delete certain lines of text which are duplicates.

The name I’ve given the file is today.txt, located on my desktop, and it contains a list of URLs for the NYtimes Today’s Paper. However, through parsing an html file, I receive several urls that are duplicates, like so:

http://www.nytimes.com/2012/07/06/education/no-child-left-behind-whittled-down-under-obama.html
http://www.nytimes.com/2012/07/06/business/global/markets-look-to-europes-central-bank-for-action.html
http://www.nytimes.com/2012/07/06/business/global/markets-look-to-europes-central-bank-for-action.html
http://www.nytimes.com/2012/07/06/nyregion/3-children-killed-in-long-island-boating-accident.html
http://www.nytimes.com/2012/07/06/nyregion/3-children-killed-in-long-island-boating-accident.html
http://www.nytimes.com/2012/07/06/world/americas/earthquake-relief-where-haiti-wasnt-broken.html
http://www.nytimes.com/2012/07/06/world/americas/earthquake-relief-where-haiti-wasnt-broken.html
http://www.nytimes.com/2012/07/06/us/politics/journal-critique-of-romney-shows-murdoch-doubt-on-candidacy.html
http://www.nytimes.com/2012/07/06/us/politics/journal-critique-of-romney-shows-murdoch-doubt-on-candidacy.html
http://www.nytimes.com/2012/07/06/technology/at-hacker-hostels-living-on-the-cheap-and-dreaming-of-digital-glory.html
http://www.nytimes.com/2012/07/06/technology/at-hacker-hostels-living-on-the-cheap-and-dreaming-of-digital-glory.html

I’ve been trying to remove the duplicates through a do shell script in Applescript, but I haven’t been able to make it work. Here is my code:

set delDups to do shell script "sort /Users/paolob/Desktop/today.txt | uniq -u"
return delDups

So my question:
How can I delete the duplicates in my today.txt file,
and then save the result to the same today.txt file

Any help would be very appreciated. Thank you in advance.

Edit
It would be more economical and faster if in fact the shell script, or whatever duplicate deleter you suggest, reads the text directly in Applescript Editor, and then sets the new text to a *new_text* variable, for example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:17:49+00:00Added an answer on June 7, 2026 at 10:17 am

    Try this…

    set filePath to (path to desktop as text) & "today.txt"
    set theText to read file filePath
    set textList to paragraphs of theText
    
    set uniqueList to {}
    repeat with i from 1 to count of textList
        set thisParagraph to item i of textList
        if thisParagraph is not in uniqueList then set end of uniqueList to thisParagraph
    end repeat
    
    set {tids, text item delimiters} to {text item delimiters, return}
    set uniqueText to uniqueList as text
    set text item delimiters to tids
    
    set openFile to open for access file filePath with write permission
    set eof of openFile to 0
    write uniqueText to openFile starting at eof as text
    close access openFile
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have written applescript to get file name. on open of thisPDF set
I'm trying to write a simple AppleScript to do some text manipulation on the
I have created a custom AppleScript that works, and placed it in the folder:
I have a Cocoa-AppleScript project in XCode where I'm trying to send some commands
I have this applescript that takes the selected item and zips that file/folder and
I've created the following AppleScript for deleting all the selected tracks: property okflag :
I have written an AppleScript which when supplied with a Windows network link, will
I have an AppleScript program which creates XML tags and elements within an Adobe
I tried to create an AppleScript that reads a text file and puts the
I have such an AppleScript: tell application Firefox activate set the bounds of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.