Extracting segments


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting segments
# 1  
Old 11-19-2014
Extracting segments

I have queue.txt with the following contents:

Code:
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:
Code:
APSAUTOCODER    5000
APSCASERETRIEVAL  5000
and so on

Appreciate your help!

Last edited by vbe; 11-19-2014 at 11:45 AM..
# 2  
Old 11-19-2014
One way with awk and tr:
Code:
awk ' /^Queue/ {printf ("%s ", $2)}
         /max queue depth/ {print $3} ' infile  | tr -d '[:punct:]' > newfile


On solaris use nawk and /usr/xpg4/bin/tr
These 2 Users Gave Thanks to jim mcnamara For This Post:
# 3  
Old 11-19-2014
Quote:
Originally Posted by Daniel Gate
I have queue.txt with the following contents:

Code:
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:
Code:
APSAUTOCODER    5000
APSCASERETRIEVAL  5000
and so on

Appreciate your help!
Hello Daniel Gate,

Following may help you in same too.

Code:
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.
Code:
APSAUTOCODER  5000
APSCASERETRIEVAL  5000

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 4  
Old 11-19-2014
jim,
nice and clear approach Smilie
I guess print $3 should be print $5, because $3 is "depth" in the particular line.
This User Gave Thanks to junior-helper For This Post:
# 5  
Old 11-19-2014
Awk is great.

Bash trys...
Code:
#!/bin/bash

while read x
do
    [[ $x =~ ^Q ]] && ttl=${x##*'['}
    [[ $x =~ ^"max queue depth" ]] && printf "%s %s\n" ${ttl%]*} ${x##*:}
done < ./queue.txt

This User Gave Thanks to ongoto For This Post:
# 6  
Old 11-19-2014
Truly appreciate great solutions! Thank you again!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep start and end line of each segments in a file

Cat file1 -------- ---------- SCHEMA.TABLE1 insert------- update----- ------------- ---------- SCHEMA.TABLE2 insert------- update----- ----------- ------------ SCHEMA.TABLE3 insert------- update----- ------------ grep -n SCHEMA > header_file2.txt (2 Replies)
Discussion started by: Veera_V
2 Replies

2. SuSE

TCP segments retransmission

Hi all, I got an application that is running on SUSE Linux. I would like to get some data about the number of TCP segments retransmission on a particular interface. Is there any way I can get that? Thanks, (2 Replies)
Discussion started by: Pouchie1
2 Replies

3. Shell Programming and Scripting

Averaging segments and including the name

Hello, I have a awk line that averages rows. So if my file looks like this: Jack 1 1 1 1 1 1 Joe 1 1 1 1 1 1 Jerry 0 0 0 0 0 0 John 1 1 1 0 0 0 The awk line below skips column 1 and then averaged the rows awk -F'\t' -v r=3... (3 Replies)
Discussion started by: phil_heath
3 Replies

4. Shell Programming and Scripting

Averaging segments

Hi, I have a file that I want to average. So specifically I want to average every third column for each row. Here is an example of my file 2 2 2 3 3 3 1 1 1 5 5 5 Heres what I want it to look like after averaging every third column 2 3 1 5 thanks (11 Replies)
Discussion started by: kylle345
11 Replies

5. Programming

C programming - Memory Segments

Can someone tell me how many bytes are allocated for C segments(text,data,heap,stack). (3 Replies)
Discussion started by: nandumishra
3 Replies

6. Shell Programming and Scripting

Compare EDI files by skipping selected Segments

Hi, I wanted to compare EDI files present in Two different Directories which can be related by the file names. While comparing the EDI files i have to skip selected segments such as "ISA" "IEA" and "GS" "GE" since this may have datetime stamp and different "Sender" "Receiver" Qual. and... (3 Replies)
Discussion started by: Sivas
3 Replies

7. Programming

Write into shared memory segments

I have created a shared memory segment (which size is 64 bytes) using shmget, shmat e.t.c and i want to divide it into 2 areas. One area for input data and one area for output? How can i do that? Furthermore, When i have to write my input data into the shared memory segment i want to write... (3 Replies)
Discussion started by: mae4
3 Replies

8. HP-UX

HP-UX Trying to Understand Shared Memory Segments

I am fairly new to HP-UX and trying to get a better understanding of the operating system. While poking around a bit I find myself questioning whether I should be concerned about Shared Memory segments with missing CPID and LPID? For example: ipcs -mp IPC status from /dev/kmem as of Mon Mar... (2 Replies)
Discussion started by: scotbuff
2 Replies

9. Shell Programming and Scripting

[Splitting file] Extracting group of segments from one file to others

Hi there, I need to split one huge file into separate files if the condition is fulfilled according to that the position between 97 and 98 matches with “IT” at the segment MAS. There is no delimiter file is fix-width with varous line length. Could you please help me how I do split the file... (1 Reply)
Discussion started by: ozgurgul
1 Replies

10. HP-UX

Shared Memory segments

Hello.... AIX has a limit of 11 shared memory segments per process, does any one know how many HP have?? If so how do I find that out?? Thanks in advance...... (2 Replies)
Discussion started by: catwomen
2 Replies
Login or Register to Ask a Question