4

如何在ased中获取每行字符的第一次出现grepawktrbash script

'      and      .    

从这个文件。(字符是单引号和句点)。这真的很难,我喜欢你甚至在尝试。

这样命令产生:

理想输出:

orinak
pchovi
orinak

xpt

moon

在以下文件上:

class GI_DnConstants {
        const BO_DOMAIN_NAME = 'orinak.backoffice.domain.com';
        const EX_DOMAIN_NAME = 'pchovi.extranet.domain.com';
        const WS_DOMAIN_NAME = 'orinak.www.domain.com';
        const PT_DOMAIN_NAME = '.partner.domain.com';
        const PTS_DOMAIN_NAME = 'xpt.partners.domain.com';
        const WS_SECURE_DOMAIN_NAME = '.secure.domain.com';
        const IMG_DOMAIN_NAME = 'moon.images.domain.com';
}
4

3 回答 3

4

如果不需要输出中的空行,则此带有“环视”的 grep 将提供您想要的:

grep -Po "(?<=')[^.']*(?=\.)" file

刚刚看到你用awk标记了这个问题

然后在输出中使用这些空行尝试这个 awk :

awk -F"['.]" 'NF>2{print $2}' file

(示例中的 awk 单行代码适用于您的输入)

于 2013-03-26T11:12:39.973 回答
1

尝试这个:

sed -n "s/.*'\([^\.]*\)\..*/\1/p" input_file.txt

跑:

$ sed -n "s/.*'\([^\.]*\)\..*/\1/p"  input_file.txt
orinak
pchovi
orinak

xpt

moon


$ sed --version
GNU sed version 4.2.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-gnu-utils@gnu.org>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
于 2013-03-26T11:02:12.667 回答
0

又快又脏:

egrep -o "'[^\.,;]+" file | cut -c2- 

注意:这不会打印空行。

于 2013-03-26T11:07:54.670 回答