2011-12-27 65 views
0
find `pwd` -type f -name "*.ksh" -exec grep -H ".ksh" '{}' \; -print 2>/dev/null 

上執行這個命令,結果是抓取KSH NAME

/home/edwprod/Partner_com/bin/edw_etl_job_load.ksh:# Program Name :  edw_etl_job_load.ksh 
/home/edwprod/Partner_com/bin/edw_etl_job_load.ksh 
/home/edwprod/Partner_com/bin/exec_housekeep_main.ksh:# Program Name  : exec_housekeep_main.ksh 
/home/edwprod/Partner_com/bin/exec_housekeep_main.ksh:# Called program : exec_housekeep.ksh 
/home/edwprod/Partner_com/bin/exec_housekeep_main.ksh:#!/bin/ksh 
/home/edwprod/Partner_com/bin/exec_housekeep_main.ksh: nohup ${SHELL_DIR}/exec_housekeep.ksh ${ROOT_ID} ${PLAN_ID} ${P_ACTION} ${LVL} & 
/home/edwprod/Partner_com/bin/exec_housekeep_main.ksh 
/home/edwprod/Partner_com/bin/retrive_pwd_edw.ksh:#  echo " USAGE=> filename.ksh appl_schema" 
/home/edwprod/Partner_com/bin/retrive_pwd_edw.ksh 
/home/edwprod/Partner_com/bin/exec_pr_truncate_hkp.ksh:# Program Name  : exec_pr_truncate_hkp.ksh 
/home/edwprod/Partner_com/bin/exec_pr_truncate_hkp.ksh:# Calling program : exec_pr_truncate_hkp.ksh 
/home/edwprod/Partner_com/bin/exec_pr_truncate_hkp.ksh 
/home/edwprod/Partner_com/bin/exec_pr_post_housekeep.ksh:# Program Name  : exec_pr_post_housekeep.ksh 
/home/edwprod/Partner_com/bin/exec_pr_post_housekeep.ksh:# Calling program : exec_pr_post_housekeep.ksh 
/home/edwprod/Partner_com/bin/exec_pr_post_housekeep.ksh 

的命令搜索所有的shell腳本,找到腳本的名稱被稱爲內。我需要從這個結果中完全獲取ksh名稱。請幫忙嗎?

+0

你的意思是不使用exec而只是使用'find \'pwd \'-type f -name「* .ksh」'? – 2011-12-27 10:39:52

+0

這將給bin文件夾內的ksh列表。我正在嘗試獲取腳本中使用的ksh。因此,如果任何腳本錯過了,我可以在開始測試/執行之前創建。 – AruM 2011-12-27 10:42:59

回答

1

你可以這樣給一個鏡頭(-E是擴展的正則表達式,-o是輸出僅匹配模式):

find `pwd` -type f -name "*.ksh" -exec grep -E -o "[a-zA-Z0-9_]*\.ksh" '{}' \; 

要獲得一個獨特的名單:

find `pwd` -type f -name "*.ksh" -exec grep -E -o "[a-zA-Z0-9_]*\.ksh" '{}' \; |sort -u 

希望這有助於!

+0

@ user1454492:感謝您的編輯! – 2012-06-27 14:57:39