perl -pe '$_=/\S/?do{chop;$_.",".<>}:""' #### 286,0 sauoq@grover:~$ perl -l054p012e'($\,$a)=($a||$\,$b||$/);$b=$\' < test.txt a,b ,c d,287,0 sauoq@grover:~$ cat test.txt a b c d 288,0 sauoq@grover:~$