Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am always typing things like this:

cat some_list_of_elements.txt | awk '{print "\047"$1"\047"}' | paste -d, -s

It takes a list of items from a file, wraps each in quotes, and merges them together in a comma-separated list.

Rather than typing out all that stuff, I'd like to do something like this:

cat some_list_of_elements.txt | csl

How can csl be implemented in bash? Is there a way to do it as an alias?

share|improve this question
alias csl="awk '{print "\047"$1"\047"}' | paste -d, -s"

then just cat whatever | csl

This seems to work, but really doesn't, for the reasons mentioned in the comments below. See them for actual, good working solutions :)

By the way, this is not ubuntu-specific, so feel free to post on if my answer doesn't work for you.

share|improve this answer
Not working for me. The awk command outputs "20007" for each line. – frankadelic Aug 9 '12 at 22:10
This works.... alias csl='awk '\''{print "\047"$1"\047"}'\'' | paste -d, -s' – frankadelic Aug 9 '12 at 22:15
@frankadelic, you could also use a function: csl() { awk '{print "\047" $1 "\047"}' - | paste -d, -s; } -- don't have to mess around with a lot of quotes and backslashes. I explicitly put the argument - for awk to denote that it's reading from stdin. – glenn jackman Aug 10 '12 at 0:36
@roadmr, the difficulty is you're using double quotes as the "outer" quotes, so the $1 is getting substituted at the time you're defining the alias. – glenn jackman Aug 10 '12 at 0:37
up vote 0 down vote accepted

This worked for me:

alias csl='awk '\''{print "\047"$1"\047"}'\'' | paste -d, -s'

Thanks to @roadmr for pointing me in the right direction.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.