Shell技巧 三行并为一行

将以下三行并为一行,并用,号分隔。
mail: Admin@sh163.net
mailQuota:
userPassword:: c2VjcmV0
mail: Admin@sh163.net
mailQuota:
userPassword:: c2VjcmV0
mail: zentai@sh163.net
mailQuota: 10000
userPassword:: e2NyeXB0fWhDM21NNm1zQUtBUXc=
mail: sh163@sh163.net
mailQuota: 10000
userPassword:: e2NyeXB0fUtuQW50NEx6TS4zRG8=
mail: sh8163@sh163.net
mailQuota: 50000
userPassword:: e2NyeXB0fUtuLmVpUTNDTkNUeTI=
 
 
方法一:
awk '{if (NR%3==0) {print} else {printf "%s,",$0}}' aaa
 
mail: Admin@sh163.net,mailQuota: ,userPassword:: c2VjcmV0
mail: Admin@sh163.net,mailQuota: ,userPassword:: c2VjcmV0
mail: zentai@sh163.net,mailQuota: 10000,userPassword:: e2NyeXB0fWhDM21NNm1zQUtBUXc=
mail: sh163@sh163.net,mailQuota: 10000,userPassword:: e2NyeXB0fUtuQW50NEx6TS4zRG8=
mail: sh8163@sh163.net,mailQuota: 50000,userPassword:: e2NyeXB0fUtuLmVpUTNDTkNUeTI=
 
 
方法2:
sed '/mail:/ !N;s/\n/, /' user.txt  | sed '$!N;s/\n/, /'
 
结果如下:
mail: Admin@sh163.net, mailQuota: , userPassword:: c2VjcmV0
mail: Admin@sh163.net, mailQuota: , userPassword:: c2VjcmV0
mail: zentai@sh163.net, mailQuota: 10000, userPassword:: e2NyeXB0fWhDM21NNm1zQUtBUXc=
mail: sh163@sh163.net, mailQuota: 10000, userPassword:: e2NyeXB0fUtuQW50NEx6TS4zRG8=
mail: sh8163@sh163.net, mailQuota: 50000, userPassword:: e2NyeXB0fUtuLmVpUTNDTkNUeTI=
mail: chfling@sh163.net, mailQuota: 10000, userPassword:: e2NyeXB0fXdWN25HdFAzVHlQU2M=
 
方法3:
ultraedit32下记录宏和执行宏。
 

你可能感兴趣的:(职场,休闲)