How to copy columns data from your database IDE (DataGrip, Navicat) into Comma-separated values
Ok, What the problem was? many of times, I wanted to copy data from a column and use them as the IN condition part from another query. Here is an example:


So, the first solution was to develop such feature in DataGrip IDE, but since I was using another database tools such Navicat. I thought it was good (and fun!) to somehow define another shortcut for copying (or pasting) shortcut to have this feature anywhere I want. At this very first time, I have no clue how to do it, So let’s get our hands dirty.
Perfect, took me 20 minutes to find the solution. Here’s the steps I went thorough:
- I found a tool that gives me the content of the clipboard. It turns out the best is
xclip - I converted every new line character with comma using
trfamous tool! - And finally, I trimmed the last comma using lovely
sed
So here’s the command that I got after this step:
xclip -o -selection clipboard | tr '\n' ',' | sed 's/,$//g'Now just two steps remaining:
- adding a command for typing the result using
xdotool - assigning a shortcut key to the script, something like
Ctrl+Alt+v
Awesome, so the final version of the script is:
#!/bin/sh
sleep 0.5
xdotool type $(xclip -o -selection clipboard | tr '\n' ',' | sed 's/,$//g')And finally, assigning it to Ctrl+Alt+V did the magic:

If I had the time, I will definitely make a debian package out of it!
