开发者

Display contents of a file in the parent directory

I have a command which lists Weblogic instances directories on a server.I want to display contents of a file in the parent directory of each directory listed.

开发者_如何学Go

An additional feature would be to display the name of the file in addition to displaying the contents

/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

The output of the above command looks like this

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

I want to see the contents of somefile.cf files in the /opt/<some_directory>/<domain_name>/ directories i.e. /opt/<some_directory>/<domain_name>/somefile.cf

To put it simply, I need a sed regex to replace the last directory name from the output.

I tried this as well

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

but I am sure the while part and the last sed part can be done away easily using a simple sed command like this

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


/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

or do you mean the directory one level up??

/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


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


works on 8, may need tweaked for 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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜