zl程序教程

您现在的位置是:首页 >  工具

当前栏目

sed命令

命令 sed
2023-09-27 14:29:13 时间

-- 替换 空格和左圆括号为\x1

sed -i 's/ (/\x1/' 0928.txt

-- 替换 右园括号和空格和左中括号为\x1
sed -i 's/) \[/\x1/' 0928.txt

 

2017-09-28 09:46:10.179 (5352) [50001] LOG:create global entity [RewardManager, 8]

目标替换 (5352) [50001] LOG 为\x15352\x150001LOG

2017-09-28 09:46:10.179\x15352\x150001LOG:create global entity [RewardManager, 8]

 

====================
TEST:sed里面(不需要转义符\,但是正则表达式的要转义符
====================
echo ' (5352) [50001] LOG' | sed 's/\( (\)\([0-9]*\)\() \[\)\([0-9]*\)\(\] \)LOG/\x1\2\x1\4\x1LOG/g'
echo ' (5352) [50001] LOG' | sed 's/\( (\)\([0-9]*\)/\x1\2/'

 

====================

直接只去需要的LOG。cat选择特定日期的文件,grep选择特定的行,

awk把前面4列去掉,再用sub把“LOG:”和之前的空格替换掉,这样某行剩下的数据都是需要的

====================

cat hall.20001.log.2017-9-28 | grep '2017-.*LOG:.*|.*' | awk '{$1="";$2="";$3="";$4="";sub("    LOG:", "");print}' > 20001.txt