2番目のコマンドでは、「grep」および「grep」の出力を変数として使用してフォルダのユーザーIDを取得します。

2番目のコマンドでは、「grep」および「grep」の出力を変数として使用してフォルダのユーザーIDを取得します。

次のコマンドを使用して、使用したディスクの割合を取得しましたdf -h| grep workfld。最も多くのディスク容量をパーセンテージとして最上位フォルダをインポートするのではなく、最後の部分は最後のコマンドのdu -h /saswork | sort -rh | head -20出力/結果を使用してフォルダであるユーザーをgrepインポートすることです。USERIDここでコードを読みやすくするために、いくつかの手順に分けてください。

df -h| grep saswork
du -h /saswork | sort -rh | head -20
ls -la|  grep %OUTPUT_FROM_COMMAND_2%

最初の5つのフォルダを繰り返して、そのフォルダのユーザーIDを取得できるように、これを行う正確で最も簡単な方法は何ですか?

したがって、2番目のコマンドの結果は次のようになります。 569G/saswork/SAS_work438800007078_prdsasgridn03/SAS_work9A0700007078_prdsasgridn03 569G/saswork/SAS_work438800007078_prdsasgridn03

ただし、上位20件の結果があります。 3番目のコマンドで入力として使用したい部分は、上の太字のフォルダ名です。これが3番目のコマンドに入るべき内容なので、3番目のコマンドは次のようになります。

ls -la|  grep SAS_work438800007078_prdsasgridn03

このコマンド出力はユーザーIDを提供します。実行した2番目のコマンドの出力から生成された各フォルダ名に対してこのコマンドを実行したいと思います。

より正確な例を追加

Input: df -h| grep saswork
Output: /dev/mapper/vg_saswork--prd-lv_sas--saswork 3.1T 2.2T 861G 73% 
/saswork

Input: du -h /saswork | sort -rh | head -20
Output: 
569G/saswork/SAS_work438800007078_prdsasgridn03/SAS_work9A0700007078_prdsasgridn03

569G /saswork/SAS_work438800007078_prdsasgridn03 526G/saswork/SAS_work445F00002079_prdsasgridn01/SAS_work189900002079_prdsasgridn01 526G/saswork/SAS_work445F00002079_prdsasgridn01 30 d n04/SAS_work154B00007B7E_prdsasgridn04 165G/saswork/SAS_workBD3300007B7E_prdsasgridn04 134G/saswork/SAS_work36E800005097_prdsasgridn04 4 134G /saswork/SAS_work36E800005097_prdsasgridn04 110G /saswork/SAS_workB87B00002026_prdsasgridn01/SAS_workD37900002026_prdsasgridn01 1 SAS_ workB87B00002026_prdsasgridn01 105G/saswork/SAS_work55C800001BDA_prdsasgridn01/SAS_work849500001BDA_prdsasgridn01 105G/saswork/SAS_work /SAS_work3FB700003AAF_prds asgridn03/SAS_work8268 00003AAF_prdsasgridn03 57G /saswork/SAS_work3FB700003AAF_prdsasgridn03 55G/saswork/SAS_work8 9000068D9_prdsasgrid n01 55G /saswork/SAS_work87440000 68D9_prdsasgridn01 46G/saswork/SAS_work400B00002BFF_prdsasgridn02/SAS_work668100 02 46G /saswork/SAS_work400B00002BFF_ prdsasgridn02 40G/saswork/ SAS_work67780000280E_prdsasgridn02/SAS_work91E90000280E_prdsasgridn02

Input: ls -la|  grep **SAS_work438800007078_prdsasgridn03** NOTE: The 
foldername SAS_work438800007078_prdsasgridn03 came from one of the results 
from the second command output. That's where I need to pull it from for each 
one.
Output: drwx------. 3 **g6753** ereapp 3864 Jul 12 12:25 
AS_work438800007078_prdsasgridn03
Note - bold in this line is the ID of the developer that I need.

ベストアンサー1

コマンドの結果を変数に保存するには、 ``または$()の間にコマンドを入れます。

yourvar=`date +%Y`

または

yourvar=$(date +%Y)

yourvarは現在の年(2018)の値を持ちます。コマンドから直接結果を実行することもできます。

ls -la|  grep `date +%Y`

または

ls -la|  grep $(date +%Y)

必要なものを達成するためにforループを使用してください。

for i in `du -h |sort -rh|awk '{print $2}'|sed "s/.\///g"`;do ls -la |grep $i|awk '{print $3 " " $9}';done

このコマンドはおおよその例なので、重複を避けるために調整が必要な場合があります。ディレクトリに子ディレクトリがある場合、同じ親ディレクトリの出力が異なるためです。

おすすめ記事