[英]Display contents of a file in the parent directory
我有一個列出服務器上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'
但是我敢肯定,使用這樣的簡單sed命令可以輕松地將while部分和最后一個sed部分刪除掉
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
還是您的目錄向上一級?
/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\\///' -e 's/$/somefile.cf/' | sort | uniq
/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
適用於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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.