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>/

/opt/<some_directory>/<domain_name>/ディレクトリ内の somefile.cf ファイルの内容を確認したい/opt/<some_directory>/<domain_name>/somefile.cf

簡単に言うと、出力の最後のディレクトリ名を置き換える sed regex が必要です。

私もこれを試しました

/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

または、1レベル上のディレクトリを意味しますか?

/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

8 で動作しますが、10.2 では微調整が必​​要な場合があります

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

于 2010-03-22T14:40:57.520 に答える
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 に答える