0

我有一个命令列出服务器上的 Weblogic 实例目录。我想在列出的每个目录的父目录中显示文件的内容。

除了显示内容之外,另一个功能是显示文件的名称

/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed -e 's/weblogic.policy//' -e 's/security\///' -e 's/dep\///' | sort

上述命令的输出如下所示

/opt/<some_directory>/<domain_name>/<app_name>/
/opt/<some_directory>/<domain_name>/<app_name>/

我想查看目录中 somefile.cf 文件的内容,/opt/<some_directory>/<domain_name>//opt/<some_directory>/<domain_name>/somefile.cf

简单地说,我需要一个 sed 正则表达式来替换输出中的最后一个目录名。

我也试过这个

/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed -e 's/weblogic.policy//' -e 's/security\///' -e 's/dep\///' | sort | while read -r DIR ; do dirname $DIR ; done | uniq | sed 's/$/\/somefile\.cf/g'

但我确信 while 部分和最后 sed 部分可以使用这样的简单 sed 命令轻松完成

sed -e 's/<regex_for_last_directory_name>/somefile.cf/'
4

3 回答 3

2
/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed -e 's/weblogic.policy//' -e 's/security\///' | sort | while read -r DIR
do
  cat "$DIR"/somefile.cf
done

还是您的意思是上一级目录?

/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed -e 's/weblogic.policy//' -e 's/security\///' | sort | while read -r DIR
do
  cat "$DIR"/../somefile.cf
done
于 2010-03-21T05:35:50.853 回答
0

/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed -e 's/weblogic.policy//' -e 's/security\///' -e 's/$/somefile.cf/' | sort | uniq

于 2010-03-22T12:55:03.213 回答
0

适用于 8,可能需要针对 10.2 进行调整

cat $(/usr/ucb/ps auwwx | grep weblogic | tr ' ' '\n' | grep security.policy | grep domain | awk -F'=' '{print $2}' | sed -e 's/weblogic .policy//' -e 's/security///' -e 's/$/somefile.cf/' | sort | uniq)

于 2010-03-22T14:40:57.520 回答