本文已参与「新人创作礼」活动,一起开启掘金创作之路。
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /opt/hadoop-2.7.7/logs/
a1.sources.r1.includePattern = .*log$
#a1.sources.r1.includePattern = ^hadoop-root-namenode.*
# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = /tmp/flume
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
Flume 中过滤 以什么结尾的文件 a1.sources.r1.includePattern = .*log$
Flume 中过滤 以什么开头的文件 a1.sources.r1.includePattern = ^hadoop-root-namenode.*
^ $在正则表达式的作用
在正则中 ^ 表示匹配字符串的开始位置
‘12a21’.replace(/^\d/g,’’)
// 输出结果为 2a21 只有字符串开始位置的’1’被匹配到,但’a’后面的’21’没有匹配到
‘12222a21’.replace(/^\d{2}/g,’’)
// 输出结果为 “222a21” 字符串开始位置的’12’被匹配到,但’a’后面的’21’没有匹配到两位数字被匹配到
‘12222a21’.replace(/^\d{2,}/g,’’)
// 输出结果为 “a21” 字符串开始位置的数字都被匹配到,但’a’后面的’21’没有匹配到两位数字被匹配到
‘12222a21’.replace(/\d{2,}/g,’’)
// 输出结果为 “a” 字符串中所有的数字都被匹配到
但是当 ^ 在中括号中时,不在表示匹配开始位置,而是表示不匹配某字符集合
‘122ss22a2b1’.replace(/[^\d]/g,’’)
// 输出结果为:“1222221”,非数字的所有字符都被匹配
在正则中/g 表示替换将针对行中每个匹配的串进行,否则则只替换行中第一个匹配串
‘12222a21’.replace(/[\d]/,’’)
// 输出结果为:“2222a21” ,只有第一个数字被替换
‘12222a21’.replace(/[\d]/g,’’)
// 输出结果为:“a”,所有被匹配的数字都被替换
在正则中 $ 表示匹配末尾位置
‘12222a21’.replace(/[\d]$/g,’’)
//输出结果为:“12222a2”,只有末尾的1匹配
‘12222a21’.replace(/[\d]{1,}$/g,’’)
//输出结果为:“12222a” ,所有末尾被匹配