1.awk
文件如下:
[root@hadoop9 2012-05-14]# more game.log
gid,sid,user,roleid,time,user_yx,level,map_id,dept,account,sign
38,1,160476604,9318018,1336928912,13793129,41,20009,11,38,87a197f11e0c112f70d575cc16efbaf9
38,1,320344517,9314868,1336929599,13789742,78,20219,11,38,f4308249f7a4f294e54c2a3b0ff70d74
38,1,280476883,9318104,1336933167,13793225,3,20001,11,38,da5ee6883769725f4f31e655bfb36384
38,1,80476869,9318103,1336925793,13793222,3,20001,11,38,85e3d41f37c63d1b0690a07a37ce2411
38,1,280476883,9318104,1336933027,13793225,2,20001,11,38,4b2bb9fb2142b90cc52f9bccf9a7b464
38,1,80476869,9318103,1336925575,13793222,2,20001,11,38,f6250f922a3a48935c0d6b2298e21b7d
38,1,160476604,9318018,1336926263,13793129,40,20002,11,38,4e347a5f1477cbf18aa1d78c2a4c91a0
38,1,120272632,9316575,1336928385,13791580,63,20002,11,38,f8fd3fafdc06419cea4e16f1a26a8448
如要对文件进行拆分,可使用awk进行操作,具体如下:
[root@hadoop9 2012-05-14]#cat game.log | awk -F"," '{print $1 "-" $3}' >> 12.log
[root@hadoop9 2012-05-14]#cat 12.log
gid--user
38--12182990
38--11314484
38--10126864
38--10401028
38--15600037
38--10592267
38--16448167
38--13653167
38--9353487
38--11523839
38--16251657
38--8226801
38--6979269
38--10401028
38--11092155
38--10117536
38--15032794
38--10592267
38--12586649
[root@hadoop9 2012-05-14]#
2.sed
对文件进行替换操作:
[root@hadoop9 2012-05-14]#sed -i "s/--/,/g" www.log
[root@hadoop9 2012-05-14]#more www.log
gid,user
38,9873466
38,11314484
38,11268290
38,10592267
38,12182990
38,11314484
38,10126864
38,10401028
38,15600037
38,10592267
38,16448167
38,13653167
38,9353487
38,11523839
38,16251657
38,8226801
38,6979269
38,10401028
38,11092155
38,10117536
38,15032794
38,10592267
38,12586649
38,2527471