四、查询替换拦截器
功能:查询数据,替换其他数据。数据清洗过程中比较常用。
1.配置flume-查询替换拦截器配置文件:
flume-search_replace.conf
|
#1 agent a1.sources = r1 a1.sinks = k1 a1.channels = c1
#2 source a1.sources.r1.type = exec a1.sources.r1.command = tail -F /opt/plus
#查询替换拦截器 a1.sources.r1.interceptors = i1 a1.sources.r1.interceptors.i1.type = search_replace
#遇到数字改成itstar,例如:A123会替换为Aitstar a1.sources.r1.interceptors.i1.searchPattern = [0-9]+ a1.sources.r1.interceptors.i1.replaceString = itstar a1.sources.r1.interceptors.i1.charset = UTF-8
#3 sink a1.sinks.k1.type = logger
#4 Chanel a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100
#5 bind a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1 |
2.监控文件安排妥当之后,执行此配置文件
执行flume-查询替换拦截器:
[root@bigdata111 myconf]# flume-ng agent -c ../conf/ -n a1 -f flume-search_replace.conf -Dflume.root.logger=INFO,console
3.查看效果
1)查看/opt/plus文件原来的内容:

2)查看bigdata111上的flume运行结果-logger:


从这个logger上看,能够知道:对于每行替换后的结果展示是不完整的,但是综合来看,尤其是最后一个、倒数第四个的转换结果,可以看出,本次实践中的这种查找替换是将每个数【0-9】及以上的数字换成itstar-即:有一个数就换成一个itstar(如果是多位数也换成一个itstar)。
浙公网安备 33010602011771号