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 8198295
In Process

The Archive Base Latest Questions

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

I’m working on an API call with Flickr, that returns results per photo like:

  • 0

I’m working on an API call with Flickr, that returns results per photo like:

<photo id="7503362468" owner="59044395@N02" secret="66b94027db" server="8423" farm="9" title="Potluck" ispublic="1" isfriend="0" isfamily="0" />

Now, according to Flickr’s URL/API documentation, their URLs are structured like this, with the mstzb’s being one-letter indicators of the size of the photo:

http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}_[mstzb].jpg

So, my question has to do with a mass search and replace that can take each line, prepend the http://farm and then basically just “fill in the blanks” for the rest. The goal would be to use the API to fetch a restful XML that I can then throw the replacer at and have a list of URLs get generated. I have a brief familiarity with sed – admittedly no wizard at it – but I’m just unsure of how to do a search and replace per line, that prepends, then replaces in the proper order. Of course, the farm-id is the first to go into the URL, and is the fifth field in the XML – what I mean is the search and replace pattern follows the same locations for each line. Admittedly, again, I’m just getting started with regex-type stuff and any help would be appreciated. I also see that this sort of question has been asked before, but they seemed to be focused on how to create URL syntax rather than a sed-style replace. Like I said, my sed knowledge is more based around simple s/unnecessary/necessary – I am just unsure of how to pick out certain quoted fields and move them into a preformed line.

edit: A little more info – I’m using Flickr’s API Explorer to generate these XML files, and typically work with bash for editing. I think what I am after here is more along the lines of a bash script or possibly even a piece of (hopefully) executable programming language. I will hasten to add that although I do have a ‘little’ familiarity working with languages like python, I have zero to no experience with writing code aside from bash scripts. You can check out the API Explorer here: http://www.flickr.com/services/api/explore/?method=flickr.photos.search

Thanks y’all!

  • 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-07T05:55:19+00:00Added an answer on June 7, 2026 at 5:55 am

    Three solutions using awk:

    Solution 1. Assumes that every xml record looks like the sample given, with all the fields in exactly the sample’s sequence:

    The double quote is set as the field delimiter, then the desired content is accessed as positional variables within the input line.

    A file could have many input records and all will be converted in one execution.

    #!/usr/bin/awk -f
    #<photo id="7503362468" owner="59044395@N02" secret="66b94027db" server="8423" farm="9" title="Potluck" ispublic="1" isfriend="0" isfamily="0" />
    #1          2          3       4            5        6          7        8    9      `10 11     12      13         14 15        16 17        18 19
    #http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}_[mstzb].jpg
    
    #usage ./xml2url.awk <file_of_xml_text
    BEGIN {FS="\""}
    {print "http://farm"$10".staticflickr.com/"$8"/"$2"_"$6"_[mstzb].jpg"}
    

    Solution 2. This solution assumes you can edit the xml, replacing

    <photo
    

    with

    usage echo x|./xml2urlv2.awk
    

    and replacing

    />
    

    with nothing.

    Then

    #!/usr/bin/awk -f
    # usage echo x|./xml2urlv2.awk  id="7503362468"  owner="59044395@N02"  secret="66b94027db"  server="8423"  farm="9" title="Potluck" ispublic="1"  isfriend="0"  isfamily="0"
    #<photo id="7503362468" owner="59044395@N02" secret="66b94027db" server="8423" farm="9" title="Potluck" ispublic="1" isfriend="0" isfamily="0" />
    #http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}_[mstzb].jpg
    #
    {print "http://farm"farm".staticflickr.com/"server"/"id"_"secret"_[mstzb].jpg"}
    

    does the trick.

    Solution 3. This solution eliminates the need to echo anything into the script, but requires more editing. You have to put -v before each field that you care about.

    #!/usr/bin/awk -f
    #<photo id="7503362468" owner="59044395@N02" secret="66b94027db" server="8423" farm="9" title="Potluck" ispublic="1" isfriend="0" isfamily="0" />
    #http://farm{farm-id}.staticflickr.com/{server-id}/{id}_{secret}_[mstzb].jpg
    
    #usage: ./xml2urlv.awk -v id="7503362468" -v owner="59044395@N02" -v secret="66b94027db" -v server="8423" -v farm="9" -v title="Potluck" -v ispublic="1" -v isfriend="0" -v isfamily="0"  
    
    BEGIN{print "http://farm"farm".staticflickr.com/"server"/"id"_"secret"_[mstzb].jpg"}
    ### end of script 
    

    if you are new to awk, remember that the entire print statement must go on one line. Also, the { must go on the line with the word BEGIN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into

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.