0

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.

2
  • Please specify whether the answer must be bash only, or if it can use other utils like sed, or awk. Commented Apr 18, 2020 at 15:18
  • @agc anything we can use. Commented Apr 18, 2020 at 15:32

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

cat $d/A_*/ar.rt | grep "Unseen Issues" = grep -h 'Unseen Issues' "$d"/A_*/ar.rt. See porkmail.org/era/unix/award.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.