我正在使用Pig来处理数据。
我的数据如下:
<?xml version="1.0" encoding="UTF-8"?><MC><SC><S uid="1" gen="" art="Samsung" cmp="<unknown>" fld="/mnt/sdcard/Samsung/Music" alb="Samsung" ttl="Vacation"/><S uid="2" gen="" art="Samsung" cmp="<unknown>" fld="/mnt/sdcard/Samsung/Music" alb="Samsung" ttl="Mother earth"/><S uid="3" gen="" art="Samsung" cmp="<unknown>" fld="/mnt/sdcard/Samsung/Music" alb="Samsung" ttl="Over the horizon"/><S uid="4" gen="" art="Samsung" cmp="<unknown>" fld="/mnt/sdcard/Samsung/Music" alb="Samsung" ttl="Vocalise"/><S uid="5" gen="" art="Kitschi cupid" cmp="<unknown>" fld="/mnt/sdcard/Samsung/Music" alb="Samsung BeatDJ" ttl="Hard beat floor"/><S uid="6" gen="" yr="2011" art="David Kater" cmp="<unknown>" fld="/mnt/sdcard/Samsung/Music" alb="Samsung" ttl="Nothing left to say"/><S uid="7" gen="" art="Samsung" cmp="<unknown>" fld="/mnt/sdcard/Samsung/Music" alb="Samsung" ttl="Morning Dew"/><S uid="12" gen="" art="<unknown>" cmp="<unknown>" fld="/mnt/sdcard/download" alb="download" ttl="mirzaghalib6_www.songs.pk_"/><S uid="13" gen="" art="<unknown>" cmp="<unknown>" fld="/mnt/sdcard/download" alb="download" ttl="mirzaghalib7_www.songs.pk_"/><S uid="4555" gen="" yr="2012" art="Javed Ali & Shakthisree Gopalan" cmp="Music: A.R. Rahman | Lyrics: Gulzar" fld="/mnt/sdcard/WhatsApp/Media/WhatsApp Audio" alb="Jab Tak Hai Jaan" ttl="Jab Tak Hai Jaan - www.Songs.PK"/></SC><PC/></MC>)
我的目标是解析它并相互依赖地在HDFS中保存art =“”中的条目。
我使用了以下PIG命令:
A= load 'smalltestdata' USING TextLoader() AS (line:chararray);
data_split=FILTER C BY (line matches '.*art=.*');
我错过了什么吗?
答案 0 :(得分:1)
要仅在art="
之后和"
之前获取信息,请使用以下正则表达式:
(?<=art\=")(.*?)(?=")
以下是发生的事情:
1. (?<=art\=") - This is a lookbehind. It will look for matches after `art="`
2. (.*?) - This is the search string that is returned. The `?` makes it non-greedy, so it only grabs the least number of finds
3. (?=") - This is a lookahead. It will search for things before `"`
不会返回Lookbehinds和lookaheads,因此结果将是art="
和"
之间的所有文本。