简体   繁体   中英

Script usage for output

I am having 230 directories(*_t) where I need to grep "Unseen Issues" in report.rt file in all directories. I have tried this:

grep -r "Unseen Issues" *_t/A_*/ar.rt 

I got this where pf_t, pu_t, pv_t, pz_t are directories:

pf_t/A_output/ar.rt:Number of Unseen Issues      = 3
pf_t/A_output/ar.rt:adsd1p2r                50              Unseen Issues ( 1 )
pf_t/A_output/ar.rt:edsd1p2r                50              Unseen Issues ( 1 )
pf_t/A_output/ar.rt:wdsd1p2r                50              Unseen Issues ( 1 )
pu_t/A_output/ar.rt:Number of Unseen Issues      = 0
pv_t/A_output/ar.rt:Number of Unseen Issues      = 0
pz_t/A_output/ar.rt:Number of Unseen Issues      = 0

But I need the output in this way below:

pf_t
Number of Unseen Issues      = 3
adsd1p2r                50              Unseen Issues ( 1 )
edsd1p2r                50              Unseen Issues ( 1 )
wdsd1p2r                50              Unseen Issues ( 1 )

pu_t
Number of Unseen Issues      = 0

pv_t
Number of Unseen Issues      = 0

pz_t
Number of Unseen Issues      = 0

Can anyone please help me with any small script to get the output as above with using above grep command.

We can use any script can anyone please help me.

I would recommend using AWK if the intermediate text file test1.txt is important. Otherwise a shell loop is simple:

for d in *_t; do
    echo "$d"
    grep -h "Unseen Issues" $d/A_*/ar.rt
    echo ""
done

Added a test case and ran the script from command-line:

$ find * -type f
pf_t/A_output/ar.rt
pu_t/A_output/ar.rt
pv_t/A_output/ar.rt
pz_t/A_output/ar.rt


$ for d in *_t; do echo "$d"; grep -h "Unseen Issues" $d/A_*/ar.rt; echo ""; done
pf_t
Number of Unseen Issues      = 3
adsd1p2r                50              Unseen Issues ( 1 )
edsd1p2r                50              Unseen Issues ( 1 )
wdsd1p2r                50              Unseen Issues ( 1 )

pu_t
Number of Unseen Issues      = 0

pv_t
Number of Unseen Issues      = 0

pz_t
Number of Unseen Issues      = 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM