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