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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:55:42+00:00 2026-05-23T09:55:42+00:00

I’m trying to do the following. I’d like to have users provide me a

  • 0

I’m trying to do the following. I’d like to have users provide me a file that has a list of IDs in it. It would look like this:

41aeb908-dfc7-4cf8-8285-31ca184dc1c5
da877ffa-49bc-4f07-b692-4873870fcb37
a555cdd0-e100-42cb-a355-140de7958b36

The file may have 10 or 100 of these lines in there. It will vary. I would then like to feed these to a SQL Query using SQLPlus. in order to do that, I am going to need to put quotes around each of these and add commas after each line.

echo "Formatting XIDs for query..."
formattedtxs=`sed -e "s/^/'/g" -e "s/$/'/g" -e "s/$/,/g" $1`

$1 will have the filename to be worked on. Then i have a file that I will be putting these into.

select distinct tt.transaction_id||','||tt.entity_id||','||cm.user_id
from transaction_tracker tt, course_membership cm
tt.entity_id = cm.course_id and
tt.transaction_id IN (XXXXXXXX);

the idea that I had was to put those XXXXs in there as my template, have sed find that and replace it with my text.

echo "Substituting XIDs into query template..."
sed "s/XXXXXXXX/$formattedtxs/" < query.template >query.tmp

It doesn’t work because it gives the error unterminated `s’ command. I’m guess it is because my formattedtxs variable itself has single quotes in it. Any ideas? The result of the first sed command is this

'41aeb908-dfc7-4cf8-8285-31ca184dc1c5', 'da877ffa-49bc-4f07-b692-4873870fcb37', 'a555cdd0-e100-42cb-a355-140de7958b36', '2b7794f5-9811-4cf3-bd42-1d459d8cb6eb', '6133179e-4e4c-4917-a132-1ee03ab88465', '81343735-e943-4084-ab9f-86f8b5aedfa9',

Bonus points if you can get rid of that last comma.

  • 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-05-23T09:55:42+00:00Added an answer on May 23, 2026 at 9:55 am

    Save this to file “mksql.bash” or so…

    sed "s/REPLACEME/$(sed "s/.*/'&'/" | paste -s -d, -)/" < template_file.txt
    

    and use it like:

    bash mksql.bash < your_id_file
    

    will produce

    select distinct tt.transaction_id||','||tt.entity_id||','||cm.user_id
    from transaction_tracker tt, course_membership cm
    tt.entity_id = cm.course_id and
    tt.transaction_id IN ('41aeb908-dfc7-4cf8-8285-31ca184dc1c5','da877ffa-49bc-4f07-b692-4873870fcb37','a555cdd0-e100-42cb-a355-140de7958b36');
    

    the “template_file.txt” contain your sql template:

    select distinct tt.transaction_id||','||tt.entity_id||','||cm.user_id
    from transaction_tracker tt, course_membership cm
    tt.entity_id = cm.course_id and
    tt.transaction_id IN (REPLACEME);
    

    I’ve replaced the much XX..X with the “REPLACEME” because i’m lazy counting Xes

    btw, welcome in SO… 🙂

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
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 am trying to render a haml file in a javascript response like so:
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.