Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Change on stdout



2009/7/31  <tartifola@xxxxxxxxx>:
> Hi,
> I need to operate a transformation on the standard output
> of a command. The output is a list of numbers
>
> 1 5 8 ...
>
> and I like to have it transformed in
>
> a1=1,a2=5,a3=8,...
>
> Any suggestion?

If they are one number per line:
% src/fibonacci | head -n25 | { \
  integer i=1; while read num;do echo -n a$(( i++ ))=$num,; done }
a1=0,a2=1,a3=1,a4=2,a5=3,a6=5,a7=8,a8=13,a9=21,a10=34,a11=55,a12=89,a13=144,a14=233,a15=377,a16=610,a17=987,a18=1597,a19=2584,a20=4181,a21=6765,a22=10946,a23=17711,a24=28657,a25=46368,

If all numbers are one line, add -d" " to the read command.

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author