Hi All,
Random question, how would you convert a data file from a list like so:
12345
12346
12347
12348
12349
12350
... <snip 100+ lines> ...
to comma separated X columns across:
12345,12346,12347
12348,12349,12350
Why would you want to do this? The background to this is a business app which loads certain data into memory based on keys supplied via a cli utility. The cli utility's syntax looks something like:
./app_loadkeys -axxx -bxxx -d 12345,12346,12347 -exxx
./app_loadkeys -axxx -bxxx -d 12348,12349,12350 -exxx
I need to share a simple way with others to handle this task, but i'm coming up short. Due to a political concern (boo! hiss!) i can't simply drop a script in the relevant production user's home dir for other staff to use (which would seem the best way to go to my mind).
So i need to find a solution to hand this over. I have the standard unix toolset available and also a wiki for storing a �How To� page explaining the process (preferably with copy / pasteable commands).
Here's the way i do it interactively at the shell when necessary:
Although that flows perfectly logically at the shell and should be easy to memorise after a few runs through, the description of how to do it reads horribly and is totally confusing if the user is not experienced with vim. It's also a bit long winded for a task they can expect to repeat semi-frequently.
I was thinking a copy / pastable command line would be an improvement for usability, perhaps:
tr '\n' ',' < imnts.list | sed 's#,\?\([0-9]\+\)\(,[0-9]\+\)\?\(,[0-9]\+\)\?#./app_loadkeys -axxx -bxxx -d \1\2\3 -exxx\n#g'
However i think that cmd line looks v daunting for an inexperienced user. What happens if the process changes in future? It's not very maintainable, for example sometimes they will want to submit 4 keys at a time instead of 3, or 10 keys at a time. I could list out on the wiki page a copy / pasteable command for each version and they copy the one for X keys at a time as they need. Like i say, i feel i'm coming up short here.
Wish i could just drop a script in place to handle this, would take 20 mins and be done with for life.
How would you solve this? Any inspiration greatly welcomed!