[英]Combining grep and find for desired results
我試圖將在腳本中找到的文件列出為“文件大小-路徑”。 我的腳本需要過濾的是每當我給它兩個參數時,第一個是“ -u
”,那么我要查找的文件就是在文件開頭包含單詞“ Priority”的文件。 (第二個參數始終是目錄)。
到目前為止,我有這個:
if [ "$1" = -u ]
for i in `grep -ril ^Priority "$2"`
do
echo | ls -lh `grep -ril ^Priority "$i"` | cut -d" " -f5,9
done
fi
它返回第7行中的文件末尾。
但是,當我運行此:
for i in `grep -ril ^Prioridad "$1"`
do
echo | ls -lh `grep -ril ^Prioridad "$i"` | cut -d" " -f5,9
done
返回所需的結果。
如何使用第一個參數-u
和第二個目錄使用-u
來獲得第一個處理此類結果的結果?
你錯過了then
:
if [ "$1" = -u ]; then # <-- here
for i in `grep -ril ^Priority "$2"`
do
# Some more edits and trying to remove the echo/ls
# and battling against not found scenario
if grep -ril ^Priority "$i" ; then # if exists
echo "$(stat -c%s $i) $i" # stat size and File
fi
done
fi
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.