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
Related
We have total 168 sub directories all will end with doc__t extension where under these sub directories will have some files std_doc__t.lst, PA_doc_*_t_output.
So I need to check in all these sub directories is there any unseen modules in report.rpt for this I have created a small script looks like this:
#!/bin/bash
for d in *_t;
do
echo "$d"
cat $d/PA_*_output/report.rpt | grep "Unseen Module"
echo ""
done
Output of above script is:
doc_txa1_t
Number of Unseen Modules = 4
smro 1 Unseen Module ( 1 )
mapo_HDN 1 Unseen Module ( 1 )
trms7_cpo 1 Unseen Module ( 1 )
overlay 1 Unseen Module ( 1 )
Unseen Modules:
Definition : Unseen Module (line 1)
Definition : Unseen Module (line 1)
doc_fuse_t
Number of Unseen Modules = 1
Unresolved Modules:
TEF07HD18_PH_OVERLAY 4 Unseen Module ( 1 )
Unseen Modules:
Definition : Unseen Module (line 1)
Now I need to search these unseen modules(smro, mapo_HDN, trms7_cpo, overlay, TEF07HD18_PH_OVERLAY) in this path /proj/history/Unseen_Modules if these are available then we need to add below path in this file std_doc_*_t.lst which is available in all sub directories like below :
/proj/history/Unseen_Modules/TEF07HD18_PH_OVERLAY
/proj/history/Unseen_Modules/smro
/proj/history/Unseen_Modules/mapo_HDN
/proj/history/Unseen_Modules/trms7_cpo
/proj/history/Unseen_Modules/overlay
In above bash script can anyone please help me how can I do this after greping the Unseen Module and how I need to search those modules in this path /proj/history/Unseen_Modules/.
I tried this :
#!/bin/bash
path = /proj/history/Unseen_Modules
for d in *_t;
do
echo "$d"
cat $d/PA_*_output/report.rpt | grep "Unseen Module"
done
I am stuck at how to search those modules in $path.
print:
#for number in 10 11 12 13 14 15; do \
( echo "Number: $$number" ); \
( break ); \
( echo Break not working ); \
done
The output that i am getting
Number: 10
Break not working
Number: 11
Break not working
Number: 12
Break not working
Number: 13
Break not working
Number: 14
Break not working
Number: 15
Break not working
The output that i need :
Number: 10
In the posted code the 'for' loop is executed in the shell (bash ?), not by the 'make' utility.
The problem with the bash script is that the 'break' statement is running in a sub-process - as it is placed inside parenthesis '( break '). As per bash manual, control-flow commands (while, if, for, return, ...) should executed in the "main" process. It is not possible to split them across processes.
Removing the '(' should solve the problem - the loop will stop after printing 'Number: 10'.
print:
#for number in 10 11 12 13 14 15; do \
( echo "Number: $$number" ); \
break ; \
( echo Break not working ); \
done
As a side note, no need to put 'echo' statements in '( ... )'. It make the script fork unnecessary instances o bash.
Value "4" below is the number of CPU threads. Idea is to run the tasks in batch of 4 and wait until the current batch is finished before starting the next batch.
Syntax 1:
while read something; do
((++i%4==0)) && wait
(
task using something as input;
)
done < input_file.txt
Syntax 2:
while read something; do
((i=i%4)); ((i++==0)) && wait
(
task using something as input;
)
done < input_file.txt
To me they both work the same except the second one is longer. But when running in the cloud (AWS ubuntu 14.04), only syntax 1 worked. The syntax2 threw a generic syntax error at "((i=i%4));" step and it became a mystery.
"The second one is longer" doesn't help since you used pseudocode.
Maybe this will help:
while read x; do ((i=++i%4)) || wait; sleep $x & done < input_file.txt
My input_file.txt:
10
9
8
7
6
5
4
3
2
1
I am looking for a better way to do the following.
I am currently reading in up to 40 strings from a text file to build 40 variables for use in this MDFIND command (only first 2 aa_fN vars shown -- where N is a number from 1 to 40).
mdfind -onlyin "/Users/username/Documents/AAA/" "( (kMDItemUserTags == 'Gray*'cdw) && ( (kMDItemDisplayName == '*$KMVAR_aa_f1*'c) || (kMDItemDisplayName == '*$KMVAR_aa_f2*'c) ) )"
Is there a better way to do this without needing to use 40 variables?
Seems to me you'd want to approach this with a loop, something like this...
repeat with i from 1 to 40
do shell script "mdfind -onlyin \"/Users/username/Documents/AAA/\" \"( (kMDItemUserTags == 'Gray*'cdw) && ( kMDItemDisplayName == '*$KMVAR_aa_f" & i & "*'c ) )\""
-- do something with rslts
end repeat
Note: I did not test your original code for mistakes
I have this non-functioning script, before I can attempt to fix it I need to know what kind of shell this was supposed to run in.
#
set pwrs = ( 0 0 0 0 0 0 0 0 )
# pwrs[1]=1
# next=2
while ( $next < 9 )
# last = $next - 1
# pwrs[$next] = $pwrs[$last] * 2
# next = $next + 1
end
#count = 1
while ( $count <= 8 )
echo $pwrs[$count]
# count = $count + 1
end
I was able to get this to produce appropriate output using csh. I would expect tcsh to work as well.
Turns out I do have a csh available. I pasted the code into the cmdline.
There was one error. All math calculations that begin with the # char must be separated from their following variable name, hence
#count = 1
Needed to be fixed as
# count = 1
$ set pwrs = ( 0 0 0 0 0 0 0 0 )
$ # pwrs[1]=1
$ # next=2
$ while ( $next < 9 )
while? # last = $next - 1
while? # pwrs[$next] = $pwrs[$last] * 2
while? # next = $next + 1
while? end
$ # count = 1
$ while ( $count <= 8 )
while? echo $pwrs[$count]
while? # count = $count + 1
while? end
output
1
2
4
8
16
32
64
128
[oracle#localhost ~]$
See Grymoire Unix - Csh for explanation of the csh #, and $pwrs[$next] (array notation). Your specific case is not addressed, but you should be able to work it out. If you have other questions after you build small test cases that don't work, post them with sample inputs, expected outputs, and your current code and output.
Also, don't spend any more time on csh, while not as bad as some portray it, you will ultimately discover that there are problems you can't solve in csh. All of it's nice cmd-line features are included in bash, so you might want to consider using it.Finally, see Grymoire csh top 10 for detailed reasons why you want to convert this code to a newer shell.
IHTH