找出每行特定匹配的串

【问题】

 From a text file with variable number of columns per row (tab delimited), I would like to extract value with specific condition. The text file looks like:

S1=dhs    Sb=skf    S3=ghw    QS=ghr<b/>

S1=dhf    QS=thg    S3=eiq<b/>

QS=bhf    S3=ruq    Gq=qpq    GW=tut<b/>

Sb=ruw    QS=ooe    Gq=qfj    GW=uvd<b/>

I would like to have a result like:

QS=ghr<b/>

QS=thg

QS=bhf

QS=ooe

Please excuse my naive question but I am a beginner trying to learn some basic bash scripting technique for text manipulation.

【回答】

       Shell可以解决这个问题,只是代码有些难懂,这类处理用SPL的集合运算更方便些,脚本如下:


A

1

=file("/file.txt").import()

2

=A1.(~.array()).union()

3

=A2.select(pos(~,"QS"))

A1:读取文本

A2:将每条记录的字段组合成序列,再将多个序列合并

A3:选出匹配“QS”字符串的成员