使用grep / sed提取字符串的一部分 [英] Extracting a part of String using grep/sed
本文介绍了使用grep / sed提取字符串的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
dn:CN = HP_NetworkSupport,OU = groups,DC = HDFCSLDM,DC = COM
dn:CN =查看用户,OU =组,DC = HDFCSLDM,DC = COM
我只想提取CN信息,直到第一个,例如
为止:
> HP_NetworkSupport
>在上述情况下将用户
复习到另一个文件。
执行相同的命令会是什么。
解决方案使用
awk
awk -F= |,''{print $ 2}'文件
HP_NetworkSupport
评论用户
I have a file in linux with similar entries as below
dn: CN=HP_NetworkSupport,OU=groups,DC=HDFCSLDM,DC=COM
dn: CN=Review users,OU=groups,DC=HDFCSLDM,DC=COM
I would like to extract only the CN information, till the first , for ex:
> HP_NetworkSupport
> Review users
in the above case to another file.
What would be command for doing the same.
解决方案
Using awk
awk -F"=|," '{print $2}' file
HP_NetworkSupport
Review users
这篇关于使用grep / sed提取字符串的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文