to get the exact word from the file using script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to get the exact word from the file using script
# 1  
Old 03-16-2010
to get the exact word from the file using script

Hi everybody,

I have one requirment,
i have to get the particular server name from a file.
EX:
File contents will be like below..

$cat test.txt
HostAssignments->new("server1",
[
"PS_SERVER",
"REG_SERVER",
"PS_ORACLE",
"OM_G10_AUD",
"OM_G10_CAD",
"OM_G10_CHF",

HostAssignments->new("server2",
[
"OM_EM_A",
"OM_EM_B",
"OM_EM_A2",
"OM_EM_B2",
"OM_G10_AUD",
"OM_G10_CAD",
"OM_G10_CHF",
"OM_G10_DKK"
$

So in this file, i have to find out the server name under whcih server we've the below three processes
PS_SERVER
PS_ORACLE
REG_SERVER

For example, i should get the 'server1' word from the above file, as under this server i've the PS_SERVER, PS_ORACLE and REG_SERVER processes.

Can anyone please help on this?

Please let me know for any doubts on my requirment..

Thanks in advance..
Raghu..
# 2  
Old 03-16-2010
Code:
awk 'BEGIN{RS="";FS="\n"} /PS_SERVER/&&/PS_ORACLE/&&/REG_SERVER/ {split($1,a,"\"");print a[2]}' urfile

# 3  
Old 03-16-2010
Bug

thank you vm for this code, it's working..

But as i dont know the awk functionality, it will be bit difficult to debug in future to me, if i face any issues. So can you please try in shel script or any command line..?

Regards,
Raghu..
# 4  
Old 03-17-2010
Maybe something like this ?

Code:
$ 
$ cat -n test.txt
     1  HostAssignments->new("server1",
     2  [
     3  "PS_SERVER",
     4  "REG_SERVER",
     5  "PS_ORACLE",
     6  "OM_G10_AUD",
     7  "OM_G10_CAD",
     8  "OM_G10_CHF",
     9
    10  HostAssignments->new("server2",
    11  [
    12  "OM_EM_A",
    13  "OM_EM_B",
    14  "OM_EM_A2",
    15  "OM_EM_B2",
    16  "OM_G10_AUD",
    17  "OM_G10_CAD",
    18  "OM_G10_CHF",
    19  "OM_G10_DKK"
$ 
$ perl -lne '$x=$1 if /^HostAssignments.*?\("(.*?)"/; $i++ if /PS_SERVER|REG_SERVER|PS_ORACLE/; if ($i==3){print $x; $i=0}' test.txt
server1
$ 
$

tyler_durden
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 exact word

Hi I am trying to grep multiple exact word from log file and directing it to a new file. however my log file has many numeric values, such as 0400, 0401, 0404 and all html error also starts with 404, 401 etc so I just want to grep only when 404, 401 etc is coming, NOT 0400, OR 0401 i have... (8 Replies)
Discussion started by: scazed
8 Replies

2. Shell Programming and Scripting

How to take exact word from output.?

Hi i am writing and i want to take very first word "A924A5FC"from the below o/p A924A5FC 0910055313 P S SYSPROC SOFTWARE PROGRAM ABNORMALLY TERMINATED A924A5FC 0908091913 P S SYSPROC SOFTWARE PROGRAM ABNORMALLY TERMINATED A924A5FC 0906090313 P S SYSPROC SOFTWARE... (4 Replies)
Discussion started by: scriptor
4 Replies

3. Shell Programming and Scripting

How to get the exact word in awk?

Hi, i have a file that contains the following: ARTPRD01_app = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 11.222.3.4)(PORT = 1540)) (CONNECT_DATA = (SERVICE_NAME = artprd01.com) ARTPRD01 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 11.223.3.1)(PORT =... (2 Replies)
Discussion started by: reignangel2003
2 Replies

4. Shell Programming and Scripting

Grep Exact word

This may be stupid question but not able to solve it. How to grep exact word and line along with it. TEST:/u00/app/oracle/product/10.2.0/TEST:N TEST2:/u00/app/oracle/product/10.2.0/ODS:N TEST3:/u00/app/oracle/product/10.2.0/TEST:N TEST4:/u00/app/oracle/product/10.2.0/ODS:N... (4 Replies)
Discussion started by: tapia
4 Replies

5. UNIX for Dummies Questions & Answers

How to grep the exact string / word ?

Hi All, I have a text / log file which contains strings like meta777, 77, meta, 777. Now I want to write a script which can detect a string 'meta#777' in a text file & number of occurence of 'meta', number of #, number 7, 77, 777. I'm using grep -e '77' filename but no luck. It is returning... (5 Replies)
Discussion started by: adc22
5 Replies

6. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

7. Shell Programming and Scripting

Replace exact word with blank

i have a file with the below content file1.txt ALERTADMIN.FIELD ALERTADMIN.TX_ALERTS_LOG i have another file file2 ALERTADMIN.FIELD ALERTADMIN.FIELD_WS ALERTADMIN.SECTION_FIELD_WS ALERTADMIN.TX_ACCT_PROCESSING_WORK_TABLE ALERTADMIN.TX_ACCT_REVIEW_EXEC_METRICS... (2 Replies)
Discussion started by: lavnayas
2 Replies

8. Shell Programming and Scripting

Exact Word Match

I'm trying to find a exact word match but couldn't do it. ABC ABC_NE Searching for ABC_NE tried grep -w </ABC_NE/> grep "^ABC_NE$" but didn't worked , any awk variants would also help. ---------- Post updated at 08:40 AM ---------- Previous update was at 06:48 AM ---------- I... (2 Replies)
Discussion started by: dinjo_jo
2 Replies

9. Shell Programming and Scripting

Find Exact word in file

Hi ALL, I want to search one string “20 “ i.e 20 with space. But my file where I am searching this “20 “ contain some data like 120 before image file truncated 220 Reports section succeeded 20 Transaction database .prd stopped 220 Reports section completed. When I search for the... (5 Replies)
Discussion started by: Jeevan Salunke
5 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question