grep words from output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep words from output file
# 1  
Old 06-28-2011
grep words from output file

Hi,

By using shell scripit i have save output in one file. I want to grep two words named CLUSTER and CLUSQMGR from that output file. How to grep that. output file would be having below words
Code:
 
   TYPE(QCLUSTER)                          ALTDATE(2010-05-17)
   CLUSTER(QS.CL.MFT1)                 CLUSQMGR(QS.QM.BALT1)

from above file i want to get CLUSTER and CLUSQMGR only and then i want to do below syntax.

Code:
dis $CLUSQMGR $CLUSTER channel

it shoudl work like below

Code:
dis CLUSQMGR(QS.QM.BALT1) CLUSTER(QS.CL.MFT1) channel


Last edited by joeyg; 06-28-2011 at 02:45 PM.. Reason: Please wrap CodeTags around code and data
# 2  
Old 06-28-2011
Where does grep go? It is a shell/sed/awk/PERL problem!
Code:
 
sed '
  s/.*\(CLUSTER([^)]*\)).*\(CLUSQMGR([^)]*\).*/dis \2 \1 channel'
  t
  d
 ' your_file | ksh

# 3  
Old 06-28-2011
Hi Pickett,

it is little confusing and i didn't get my out put with it.
# 4  
Old 06-28-2011
Maybe it deleted all the lines because they do not look like that? Or minor typo or two:
Code:
echo '
   TYPE(QCLUSTER)                          ALTDATE(2010-05-17)
   CLUSTER(QS.CL.MFT1)                 CLUSQMGR(QS.QM.BALT1)
' | sed '
  s/.*\(CLUSTER([^)]*)\).*\(CLUSQMGR([^)]*)\).*/dis \2 \1 channel/
  t
  d
 '
dis CLUSQMGR(QS.QM.BALT1) CLUSTER(QS.CL.MFT1) channel

# 5  
Old 06-28-2011
You mean that you have a script called "dis", that you want to call with two arguments, and have them extract the information?

Code:
$ cat dis
A=${1:-CLUSTER}
B=${2:-CLUSQMGR}

sed -n "s/.*\($A([^)]*)\).*\($B([^)]*)\).*/dis \2 \1 channel/p" file1

Output:
Code:
dis CLUSQMGR(QS.QM.BALT1) CLUSTER(QS.CL.MFT1) channel

# 6  
Old 06-29-2011
@scottn:

I have output.txt. that file is like below


TYPE(QCLUSTER) ALTDATE(2010-05-17)
CLUSTER(QS.CL.MFT1) CLUSQMGR(QS.QM.BALT1)

I want only CLUSQMGR and CLUSTER only.I want to perform the command with help of output.txt.
Commans should be
dis CLUSQMGR(QS.QM.BALT1) CLUSTER(QS.CL.MFT1) channel.

Suggest me what i need to do?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep multiple words in a file with help of fixed string switch

I have multiple strings in a file which have special character $, when i search strings by ignoring $ with \ using single quotes it returns empty results. My search strings are set char_1($lock) and set new_char_clear_3($unlock) I tried searching with but it returns empty results.However... (3 Replies)
Discussion started by: g_eashwar
3 Replies

2. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

3. Shell Programming and Scripting

How to grep a log file for words listed in separate text file?

Hello, I want to grep a log ("server.log") for words in a separate file ("white-list.txt") and generate a separate log file containing each line that uses a word from the "white-list.txt" file. Putting that in bullet points: Search through "server.log" for lines that contain any word... (15 Replies)
Discussion started by: nbsparks
15 Replies

4. Shell Programming and Scripting

How to grep the desired output and output to a file?

currently I have process from a raw file to this stage ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID") ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID") ALTER TABLE... (10 Replies)
Discussion started by: jediwannabe
10 Replies

5. Shell Programming and Scripting

Grep words with spaces and save the output

I have a file that contains the schedule for a tournament with 41 teams. The team names have spaces in them. I would like to search for each teams schedule and then save that to that teams file For example Team name: "Team Two" I would like to search for all the games for "Team Two" and... (8 Replies)
Discussion started by: knijjar
8 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

Grep multiple words in a single file

Hello All, I'm a newbie/rookie in Shell scipting. I've done oracle export of a table using Export utility. When I do export, it generates 2 files. 1> .dmp file 2> .dmp.log file. In .dmp.log file I have to search for a sentence which goes like '0 records have been inserted' and then... (2 Replies)
Discussion started by: samfisher
2 Replies

8. Shell Programming and Scripting

recursively Grep particular words among lines from a file

dear experts, Could you please help me to write a command/script to find follwing: from the log file i want to grep "resCode89270200100001552311" after that only "<resultCode>40614</resultCode>" it will be like that: resCode89270200100001552311 <resultCode>40614</resultCode> ... (7 Replies)
Discussion started by: thepurple
7 Replies

9. Shell Programming and Scripting

Splitting Concatenated Words in Input File with Words from a Master File

Hello, I have a complex problem. I have a file in which words have been joined together: Theboy ranslowly I want to be able to correctly split the words using a lookup file in which all the words occur: the boy ran slowly slow put child ly The lookup file which is meant for look up... (21 Replies)
Discussion started by: gimley
21 Replies

10. Shell Programming and Scripting

How to from grep command from a file which contains matching words?

Hi all I have a file with below content (content is variable whenever new product is launched). I need form a grep command like this egrep "Unknown product|Invalid symboland so on" How to do it using a script? Unknown product Invalid symbol No ILX exch found exceeds maximum size AFX... (4 Replies)
Discussion started by: johnl
4 Replies
Login or Register to Ask a Question