Wednesday, August 17, 2011

concatenating lines in a pipe


I often have to munge multiple lines together, and I finally found a good way:

echo -e "1\n2" | awk '{ ORS="+"; print; }'

Note that this adds the separator on the end, so I have to  handle that:

echo -e "1\n2" | awk '{ ORS="+"; print; }' | awk '{ print $1 "0" }' | bc

No comments: