grep words from txt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep words from txt
# 1  
Old 08-22-2012
grep words from txt

HTML Code:
Queue [APSAUTOCODER] on node [PRODAPP1] in domain [PROD]

   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      : 11
   current queue depth    : 0
   queue depth high limit : 80
   queue depth high event : enabled
   queue depth low limit  : 20
   queue depth low event  : disabled
   message enq count      : 60079
   message deq count      : 60082
   inhibit gets           : no
   inhibit puts           : no
   creation date/time     : Wed 11-Jan-2012 01:06:11 PM
   alteration date/time   : Tue 14-Aug-2012 12:40:32 PM
   cluster name           : PROD

Queue [APSCASERETRIEVAL] on node [PRODAPP1] in domain [PROD]

   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      : 0
   current queue depth    : 0
   queue depth high limit : 80
   queue depth high event : enabled
   queue depth low limit  : 20
   queue depth low event  : disabled
   message enq count      : 261
   message deq count      : 262
   inhibit gets           : no
   inhibit puts           : no
   creation date/time     : Wed 11-Jan-2012 01:05:54 PM
   alteration date/time   : Thu 29-Mar-2012 09:43:52 AM
   cluster name           : PROD

Queue [BMDI.RESULTS] on node [PRODAPP1] in domain [PROD]

   description            : 
   type                   : local
   max message len        : 104857600
   max queue depth        : 8000
   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      : 0
   current queue depth    : 0
   queue depth high limit : 80

......  more ......
I have a txt file containing the lines above, and need to grep 2 of items (i.e. Queue [APSAUTOCODER] max queue depth : 5000) off of the file so that the output will look like:
HTML Code:
APSAUTOCODER - max queue depth : 5000
APSCASERETRIEVAL - max queue depth : 5000
BMDI.RESULTS - max queue depth : 8000
.... more ...
Please advise.
# 2  
Old 08-22-2012
Code:
awk '/Queue/ {printf("%s - ", substr($2,2,length($2)-1); next}
      /max queue depth / {print $0}  '  infile > outfile

start with that
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 08-22-2012
Hope this helps

Code:
awk '/Queue/ {gsub(/[\[\]]/,"",$2);m=$2;} /max queue depth/ {gsub(/  */," ");print m"-"$0;} ' input_file

This User Gave Thanks to msabhi For This Post:
# 4  
Old 08-22-2012
Code:
i=1
for id  `cat <file>| sed -n 's/^Queue \[([A-Z]\+)\].*/\1/'`
do
arr[$i]=$id
i=`expr $i + 1`
done
i=1
size=${arr[@]}
while [ $i -lt $size ]
do
j=`expr $i + 1`
sed -n "/Queue \[${arr[$i]}\]/,/Queue \[${arr[$j]}\]/p" > temp.txt
value=awk -F '=' '/max queue depth/{print $2} temp.txt
echo "${arr[$i]} -max queue depth:$value"
i=`expr $i + 1`
done

Does it help?

Last edited by InduInduIndu; 08-22-2012 at 02:52 PM.. Reason: code typo error
This User Gave Thanks to InduInduIndu For This Post:
# 5  
Old 08-23-2012
Thank you so much! It works perfect.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

2. UNIX for Dummies Questions & Answers

Tail -f | grep > output.txt

hi guys, I perform a sort of monitoring. I have a server running and with tail -f | grep "Searchstring"I monitor the log-file for recent specific entries. This is ok and works fine. Now, in addition I want to have my search results not posted into the shell but into a file. I tried: tail... (3 Replies)
Discussion started by: LaUs3r
3 Replies

3. Shell Programming and Scripting

How to grep the words with space between?

see I have a text like: 27-MAY 14:00 4 aaa 5.30 0.01 27-MAY 14:00 3 aaa 0.85 0.00 27-MAY 14:00 2 aaa 1.09 0.00 27-MAY 14:00 5 aaa 0.03 0.00 27-MAY 14:00... (3 Replies)
Discussion started by: netbanker
3 Replies

4. UNIX for Dummies Questions & Answers

Grep words with X doubles only

Hi! I'm trying to figure out how to find words with X number of doubles, only. I'm searching a dictionary, (one word per line). For instance, if you want to find words containing only one pair of double letters, you could do something like this: egrep '(.)\1' wordlist.txt |egrep -v '(.)\1.*(.)\2'... (3 Replies)
Discussion started by: sudon't
3 Replies

5. UNIX for Dummies Questions & Answers

Eliminate Hyphenated Words in Grep

How do you negate a literal hyphen/dash in a regex? If it's the first character inside the brackets, then it is read literally. But if you stick a caret to the left of it, to negate it, then it seems it is no longer read literally. Or whatever, it doesn't work. Nor does escaping it seem to... (3 Replies)
Discussion started by: sudon't
3 Replies

6. Shell Programming and Scripting

grep for words in file

Hi Please can you help me on this: How to grep for multiple words in a file, BUT for every word found output it to a new line. regards FR (8 Replies)
Discussion started by: fretagi
8 Replies

7. Shell Programming and Scripting

extract words from txt using perl

Hi, i will deal with txt file and i want to use perl to extract number of words from this txt ex :if the txt file is a story which contains person names and iwant to extract these names and there is something else that these names which i want perl to extract must match the words (person names) ... (2 Replies)
Discussion started by: eng_shimaa
2 Replies

8. Shell Programming and Scripting

sed to read x.txt and grep from y.txt

How would I write a command(s) to read from a file (list) that looks like this: 29847374384 and grep from a second file (list) that looks like this: 29847374384, jkdfkjdf,3833,ddd:confused: (1 Reply)
Discussion started by: smellylizzard
1 Replies

9. UNIX for Dummies Questions & Answers

Grep Three Words

I have been trying to find files containing the words AAA, BBB and CCC. I tried: grep AAA `grep BBB files*` grep CCC files* but is does not work I tried several ways this is an easy one but I am a dummy, Does anyone can help me? Thanks :( (12 Replies)
Discussion started by: murbina
12 Replies

10. Shell Programming and Scripting

find words with grep....

I have a .txt file which contains several lines of text. I need to write a script program using grep or any other unix tool so as to detect part of the text (words) between / / that begin with the symbol ~. For example if somewhere in the text appears a webpage address like... (8 Replies)
Discussion started by: chrisxgr
8 Replies
Login or Register to Ask a Question