I am very new to Grep and regular expressions. From below text output, how can I get list groups. I just want "company, it and "fun guys"". This list of groups varies.
我是Grep和正则表达式的新手。从文本输出下方,我如何获得列表组。我只想要“公司,它和”有趣的家伙“”。这个组列表各不相同。
So basically, I am looking for all the lines after "Groups:" and before "Licenses:". Also do not want anything between the the brackets (for example, i want to remove <company@domain.com>
)
基本上,我正在寻找“Groups:”之后和“Licenses:”之前的所有行。也不要在括号之间有任何东西(例如,我想删除
1 个解决方案
#1
2
This command will do it,
这个命令会这样做,
sed -n '/Groups:/,/Licenses/p' sample |sed '1d'|sed '$d' |cut -f1 -d'<'
Here is explanation,
这是解释,
sed -n '/Groups:/,/Licenses/p' sample
sed -n'/ Groups:/,/ Licenses / p'样本
Extracting text from the file sample in between two patterns as mentioned in regex above.
如上面的正则表达式中所提到的,在两个模式之间从文件样本中提取文本。
sed '1d'
Deletes the line containing "Groups:" keyword.
sed'1d'删除包含“Groups:”关键字的行。
sed '$d'
Deletes the line containing "Licenses" keyword.
sed'$ d'删除包含“Licenses”关键字的行。
cut -f1 -d'<'
Extracting the OPs mentioned patterns finally.
cut -f1 -d'<'最后提取OP提到的模式。
Output:
输出:
$ sed -n '/Groups:/,/Licenses/p' sample |sed '1d'|sed '$d' |cut -f1 -d'<'
company
it
fun guys
#1
2
This command will do it,
这个命令会这样做,
sed -n '/Groups:/,/Licenses/p' sample |sed '1d'|sed '$d' |cut -f1 -d'<'
Here is explanation,
这是解释,
sed -n '/Groups:/,/Licenses/p' sample
sed -n'/ Groups:/,/ Licenses / p'样本
Extracting text from the file sample in between two patterns as mentioned in regex above.
如上面的正则表达式中所提到的,在两个模式之间从文件样本中提取文本。
sed '1d'
Deletes the line containing "Groups:" keyword.
sed'1d'删除包含“Groups:”关键字的行。
sed '$d'
Deletes the line containing "Licenses" keyword.
sed'$ d'删除包含“Licenses”关键字的行。
cut -f1 -d'<'
Extracting the OPs mentioned patterns finally.
cut -f1 -d'<'最后提取OP提到的模式。
Output:
输出:
$ sed -n '/Groups:/,/Licenses/p' sample |sed '1d'|sed '$d' |cut -f1 -d'<'
company
it
fun guys