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

  • Home
  • SEARCH
  • 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 8960301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:38:00+00:00 2026-06-15T15:38:00+00:00

The question is a sequel to plain text URL to HTML code (Automator/AppleScript) .

  • 0

The question is a sequel to plain text URL to HTML code (Automator/AppleScript).

Suppose I have a plain txt file /Users/myname/Desktop/URLlist.txt:

title 1
http://a.b/c

title 2
http://d.e/f

...

I’d like to (1) convert all the URL (http://...) to HTML code, and (2) add

&nbsp;<br />

to each empty line, so that the aforementioned content will become:

title 1
<a href="http://a.b/c">http://a.b/c</a>
&nbsp;<br />
title 2
<a href="http://d.e/f">http://d.e/f</a>
&nbsp;<br />
...

I come to the following Applescript:

set inFile to "/Users/myname/Desktop/URLlist.txt"
set middleFile to "/Users/myname/Desktop/URLlist2.txt"
set outFile to "/Users/myname/Desktop/URLlist3.txt"

do shell script "sed 's/\\(http[^ ]*\\)/<a href=\"\\1\">\\1<\\/a>/g' " & quoted form of inFile & " >" & quoted form of middleFile
do shell script "sed 's/^$/\\&nbsp;<br \\/>/g' " & quoted form of middleFile & " >" & quoted form of outFile

It works, but it is redundant (and silly?). Could anyone make it more succinct? Can it be done involving only one text file instead of three (i.e. the original content in /Users/myname/Desktop/URLlist.txt is overwritten with the end result)?

Thank you very much in advance.

  • 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-15T15:38:02+00:00Added an answer on June 15, 2026 at 3:38 pm

    Try:

    set inFile to "/Users/myname/Desktop/URLlist.txt"
    
    set myData to (do shell script "sed '
    /\\(http[^ ]*\\)/ a\\
    &nbsp;<br />
    ' " & quoted form of inFile & " | sed 's/\\(http[^ ]*\\)/<a href=\"\\1\">\\1<\\/a>/g' ")
    
    do shell script "echo " & quoted form of myData & " > " & quoted form of inFile
    

    This will let you use the myData variable later in your script. If this is not part of a larger script and you are simply modifying your file, use the -i option as jackjr300 suggests. Also, this script looks for the original pattern and appends the new line to it rather than simply looking for empty lines.

    EDIT:

    set inFile to "/Users/myname/Desktop/URLlist.txt"
    set myData to (do shell script "sed 's/\\(http[^ ]*\\)/<a href=\"\\1\">\\1<\\/a>/g; s/^$/\\&nbsp;<br \\/>/g' " & quoted form of inFile)
    do shell script "echo " & quoted form of myData & " > " & quoted form of inFile
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a sequel to my (other) dumb question that I have asked today
This question is a sequel to this question (I have applied the answer, but
Note: This is a sequel to my previous question about powersets. I have got
This question is sort of a sequel to that question. When we want to
Question is already been asked in title. Here is a code: (function($){ var filter
Question in title pretty much sums it up. I have some resource object defined
Question: I receive the following error for the code below, does anyone know why?
In a plain .asp file, any content outside of <% %> tags is sent
I have a table with ~800k rows. I ran an update users set hash
Question is not correctly framed i know, how do i code the below logic

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.