Finding a specific word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a specific word
# 1  
Old 11-17-2010
Java Finding a specific word

Hi,

I am trying to develop a script which should find a word if a particular word exists.

Below is the content of the file.
Code:
insert_job: test_job ----> job name
days_of_week: all
start_times: "16:00"
date_conditions: 1
 
insert_job: test_job2 ----> job name
days_of_week: all
start_times: "16:00"

Now my objective is to find the job name which doesn't have date_conditions even though they have both start_times and days_of_week.

In the above sample it should display test_job2 as output as it doesn't contain days_of_week and start_times.

Thanks for your help in advance.

Regards,
rpatty

Last edited by Franklin52; 11-26-2010 at 11:07 AM.. Reason: please use code tags
# 2  
Old 11-17-2010
Code:
 
#!/bin/ksh
awk '{ if($1=="insert") printf("\n%s",$0); else printf(" %s",$0); }' input_file > temp
grep -v "date_conditions" temp | awk '{ print $2 }'


Last edited by anurag.singh; 11-17-2010 at 07:08 AM..
This User Gave Thanks to anurag.singh For This Post:
# 3  
Old 11-17-2010
Try:
Code:
awk '!/date_conditions/{print $2}' RS= infile

These 3 Users Gave Thanks to Scrutinizer For This Post:
# 4  
Old 11-17-2010
thanks for your reply on my query.
The code which you have sent is not working. As I mentioned in my query. The script needs to check whether job name(its under insert_job) contains days_of_week and start_times parameter then only it should go for checking date_conditions parameter.
If there are no days_of_week and start_times parameter for a particular job name it should skip that job.
If job name contains both days_of_week and start_times parameter and if it doesn't contain date_conditions parameter it should print job name else not.

At the end of the script it should print only job name thats under insert_job parameter.

Thanks once again for replying to my query.
# 5  
Old 11-17-2010
Code:
awk '/days_of_week/ && /start_times/ && !/date_conditions/{print $2}' RS= infile

This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 11-17-2010
Will this work for you:

Quote:
awk '$0 ~ /^$/ && job ~ /test/ {printf("%s\n",job);job="";next } /insert/ {job=$2;next} /date/ {job="";next}' input_file
This User Gave Thanks to panyam For This Post:
# 7  
Old 11-17-2010
hi Panyam,

Thanks for your reply.

Its giving me systax error after /test/. what kind of action does /test/ peforms. I am getting similar error after /insert/ and /date/ also.

Please help me on this.

Thanks,
rpatty
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

2. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

3. Shell Programming and Scripting

Need a word which just comes next to after grep of a specific word

Hi, Below is an example : ST1 PREF: int1 AVAIL: int2 ST2 PREF :int1 AVAIL: int2 I need int1 to come in preferred variable while programming and int2 in available variable Please help me doing so Best regards, Vishal (10 Replies)
Discussion started by: Vishal_dba
10 Replies

4. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies

5. Shell Programming and Scripting

Fetch entries in front of specific word till next word

Hi all I have following file which I have to edit for research purpose file:///tmp/moz-screenshot.png body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: "Liberation Sans"; font-size: x-small; } Drug: KRP-104 QD Drug: Placebo Drug: Metformin|Drug:... (15 Replies)
Discussion started by: Priyanka Chopra
15 Replies

6. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

7. Shell Programming and Scripting

Grep out specific word and only that word

ok, so this is proving to be kind of difficult even though it should not be. say for instance I want to grep out ONLY the word fkafal from the below output, how do I do it? echo ajfjf fjfjf iafjga fkafal foeref afoafahfia | grep -w "fkafal" If i run the above command, i get back all the... (4 Replies)
Discussion started by: SkySmart
4 Replies

8. Shell Programming and Scripting

tail and redirect until finding a specific word

Hey guys, I'm a new bee to this forum as well as to Unix, just having a requirement which i'm not sure how to write shell script for it.. Here is my requirement This is related to tomcat catalina.out file. Just want to display the content of this file until it finds a word like 'server... (2 Replies)
Discussion started by: new_bee
2 Replies

9. Shell Programming and Scripting

Finding a word at specific location in a string

Hi All , I have different strings (SQL queries infact) of different lengths such as: 1. "SELECT XYZ FROM ABC WHERE ABC.DEF='123' " 2. "DELETE FROM ABC WHERE ABC.DEF='567'" 3. "SELECT * FROM ABC" I need to find out the word coming after the... (1 Reply)
Discussion started by: swapnil.nawale
1 Replies

10. Shell Programming and Scripting

How to replace a specific word in specific column?

Hi My orginal file is like (100s of lines) id host ip location remarks 1 host1 ip1 - xxx 2 host2 ip2 - xxx 3 host3 ip3 - xxx -- -- 9 host9 ip9 - xxx I have a ref file like host1 location1 host2 location2 host3 location3 -- --... (6 Replies)
Discussion started by: ./hari.sh
6 Replies
Login or Register to Ask a Question