How to format content of a file to fit a SQL in-clause


SUBMITTED BY: Guest

DATE: Sept. 23, 2013, 1:41 p.m.

FORMAT: Bash

SIZE: 524 Bytes

HITS: 1978

  1. # How to format content of a file to fit a SQL in-clause:
  2. # file: username
  3. # with content:
  4. username1
  5. username2
  6. username3
  7. username4
  8. username5
  9. # This is how to make it fit the SQL in clause:
  10. sed "s/^/'/;s/$/',/;$ s/,$//" username
  11. # output looks like:
  12. 'username1',
  13. 'username2',
  14. 'username3',
  15. 'username4',
  16. 'username5'
  17. # now use output in your SQL statement
  18. select * from users where user_name in
  19. (
  20. <insert output here>
  21. )

comments powered by Disqus