I have queue.txt with the following contents:
Queue [APSAUTOCODER] on node ...
description :
type : local
max message len : 104857600
max queue depth : 5000
queue depth max event : enabled
persistent msgs : yes
backout threshold : 0
msg delivery seq : priority
queue shareable : yes
open input count : 1
open output count : 24
current queue depth : 0
queue depth high limit : 80
<snipped....>
Queue [APSCASERETRIEVAL] on node ....
description :
type : local
max message len : 104857600
max queue depth : 5000
queue depth max event : enabled
persistent msgs : yes
I need to extract Queue [APSAUTOCODER] and max queue depth : 5000, Queue [APSCASERETRIEVAL] and max queue depth : 5000, and so on.
Please let me know how to extract the segments so that I can have:
APSAUTOCODER 5000
APSCASERETRIEVAL 5000
and so on
Appreciate your help!
One way with awk and tr:
awk ' /^Queue/ {printf ("%s ", $2)}
/max queue depth/ {print $3} ' infile | tr -d '[:punct:]' > newfile
On solaris use nawk and /usr/xpg4/bin/tr
2 Likes
Hello Daniel Gate,
Following may help you in same too.
awk -F":" '/^Queue/ {gsub(/.*\[/,X,$0);gsub(/\].*/,Y,$0);S=$0;A=1} {if(A && ($0 ~ /max queue depth/)){print S OFS $2;A=0}}' Input_file
Output will be as follows.
APSAUTOCODER 5000
APSCASERETRIEVAL 5000
Thanks,
R. Singh
1 Like
jim,
nice and clear approach
I guess print $3 should be print $5, because $3 is "depth" in the particular line.
1 Like
ongoto
5
Awk is great.
Bash trys...
#!/bin/bash
while read x
do
[[ $x =~ ^Q ]] && ttl=${x##*'['}
[[ $x =~ ^"max queue depth" ]] && printf "%s %s\n" ${ttl%]*} ${x##*:}
done < ./queue.txt
1 Like
Truly appreciate great solutions! Thank you again!