FILE.txt的示例内容如下所示。我如何修改SED使用的正则表达式来执行捕获,从而产生所需的输出节?如果可能,最好使用POSIX awk或sed函数。我已经考虑完全使用AWK来完成这个工作,但是我没有遵循如何使用它提供的选项创建与捕获相同的行为。带捕获sed/awk正则表达式 - 如何让一个简单的正则表达式工作?
一个我碰到的尝试各种解决方案的问题是如何使双引号可选。
sed -e 's/.Include .*"*\(.*\)"*/\1/g' FILE.txt
FILE.txt
##########################################################################
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI Multiviews
# Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
# Possible values include: debug, info, notice, warn, error, crit,
# does not include the trailing slash.
AddOutputFilter INCLUDES .shtml .html
Options -Indexes FollowSymLinks Includes
LoadModule include_module modules/mod_include.so
Include /opt/file.conf
Include "/opt/file.conf"
Include /usr/bin/abcOutput.conf
Include /usr/bin/ed_Output.conf
###########################################################################
**Desired Output:**
/opt/file.conf
/opt/file.conf
/usr/bin/abcOutput.conf
/usr/bin/ed_Output.conf
12问题,并在只有2接受。请看看:?当有人回答我的问题,我应该怎么办(http://stackoverflow.com/help/someone-answers) – Cyrus
你** **真的希望这些'###### ################################################## ###################'行会出现在输出中?如果没有,解决你的问题。 –
删除正则表达式开头处的'.',对于初学者。您还需要进行匹配的是,关闭双引号的工作 - 使用'[^“]的*''而不是*' - ! –