Finding a specific word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding a specific word
# 8  
Old 11-17-2010
can you try with:

Quote:
nawk or /usr/xpg4/bin/awk on Solaris.
# 9  
Old 11-17-2010
i am working on Linux operationg system
# 10  
Old 11-18-2010
Code:
 
[ravi@testbox ~]$ uname -a
Linux testbox 2.6.20-1.2948.fc6 #1 SMP Fri Apr 27 19:18:54 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux
 
[ravi@testbox ~]$ cat input_file
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"
 
insert_job: test_job3 ----> job name
days_of_week: all
start_times: "16:00"
date_conditions: 1
 
insert_job: test_job4 ----> job name
days_of_week: all
start_times: "16:00"
 
[ravi@testbox ~]$  awk '$0 ~ /^$/ && job ~ /test/ {printf("%s\n",job);job="";next } /insert/ {job=$2;next} /date/ {job="";next}'  input_file
test_job2
test_job4

Hence , it works in linux too!
# 11  
Old 11-19-2010
Thanks alot Ravi. It working. I really appreciate your help.

Take care and have a great weekend..:-)
# 12  
Old 11-25-2010
Java Removing a line which is having blank spaces

I am facing a new problem. I want to remove line which is having blank space above and below to it.

Below is the sample file.
Code:
insert_job: fsetlbqa_fsw_ibsfile_box job_type: b
date_conditions: 1
start_times: "09:00"
 
insert_job: fsetlbqafsw028ibsetlfile job_type: c
 
insert_job: fsetlbqa_fsw_ETLB_spc_rep_box job_type: b
date_conditions: 1
days_of_week: mo,tu,we,th,fr,sa,su
start_times: "06:00"
 
insert_job: fsetlbqafswW999spacereport job_type: c



My output should be
Code:
insert_job: fsetlbqa_fsw_ibsfile_box job_type: b
date_conditions: 1
start_times: "09:00"
 
insert_job: fsetlbqa_fsw_ETLB_spc_rep_box job_type: b
date_conditions: 1
days_of_week: mo,tu,we,th,fr,sa,su
start_times: "06:00"


I want to remove the lines which are blank spaces above and below to the line. I am trying to get it done by using sed. But i am not getting correct solution.

Last edited by Franklin52; 11-26-2010 at 11:08 AM.. Reason: please use code tags
# 13  
Old 11-25-2010
Love Scrutinizer solution, anyway if you want to "give a try" to perl you will notice it's Extensibility:

Code:
#!/usr/bin/env perl

open(DAT, shift) || die("Could not open file!");
@data=<DAT>;
close(DAT);
foreach ( @data ) {
   chomp;
   if ( /([^:]+):\s*(.*)/ ) {
      $key=$1;
      $value=$2;
      $name=$value if ( $key =~ /insert_job/ && $value ne $name ) ;
      $job{$name}{$key}=$value;
      }
   }

foreach $name ( sort keys %job ) {
      if  ( ! $job{$name}{date_conditions} ) {
         print $name."\n";
         }
   }

Usage:
Code:
script file

# 14  
Old 11-25-2010
something like this on the i/p file to remove the "insert" lines preceeded and followed by blank lines.

Code:
 
awk '/^$/ {p=1;q="";next} /insert/ {q=$0;next} q { print q;q=""} 1' input_file

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: &quot;Liberation Sans&quot;; 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