Today, I was helping a co-worker with a script. He needed to find some set of directories, add /*.jar to the end of each, and put them together in a single line as coma-separated values.
Enter paste! (Funny thought, typing 'man paste' into google turned out much better than I thought it would!)
Say we had a list of all the files on my RaspberryPi's home directory, and we wanted to put them together as a comma separated list... We would simply pipe them through paste with the --delimiters=, and --serial flags set.
$ ls ~/Desktop/ | paste -d, -s
debian-reference-common.desktop,idle3.desktop,idle.desktop,lxterminal.desktop,midori.desktop,ocr_resources.desktop,paste.out,pistore.desktop,python-games.desktop,scratch.desktop,shutdown.desktop,sonic-pi.desktop,wolfram-language.desktop,wolfram-mathematica.desktop,wpa_gui.desktop
Even though I've been using linux since about 2003, I feel like I stumble onto little nuggets like this pretty often!
No comments:
Post a Comment