Script to ignore word from a line ...


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Script to ignore word from a line ...
# 1  
Old 05-20-2010
Script to ignore word from a line ...

Hi Gurus,
I'm need of a script in which we are finding an independent word ‘boy' in a log file. We are using grep in order to do the same. Now in this log file there are some sentences where we see ‘This is a boy' and we do not want to count word ‘boy' from this sentence.
So in other word we want to grep only independent word ‘boy'. We have script for this part but in this script results are not accurate because it is gathering word ‘boy' from sentence ‘This is a boy' also.
Is there any way that I can count all word ‘boy' from sentence ‘This is a boy' and this count can be subtract from total count of boy?
Thanks in advance.
Hey
# 2  
Old 05-20-2010
Question Confused by your request

Are you simply looking for instances where the word boy exists alone on a line?
Thus:
example-->
Code:
boy
this is is boy
this is a girl
boy oh boy

>>is count of 1 (one)

And, what is your current command that is not working correctly?
# 3  
Old 05-20-2010
Using either "sed" or cascaded "grep"s (one "grep" piping its output into another "grep") you could first match all lines containing "boy" and then filter out from the resulting set all lines containing "This is a boy." For instance:

Code:
sed -n '/boy/ {
          /This is a boy\./ !p
          }' /path/to/inputfile

Alternatively, cascaded "grep"s (which will be slower than the first solution):

Code:
grep 'boy' /path/to/inputfile | grep -v 'This is a boy\.'

Counting the lines printed this way is left as an exercise to the reader. ;-))

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script using awk to find and replace a line, how to ignore comment lines

Hello, I have some code that works more or less. This is called by a make file to adjust some hard-coded definitions in the src code. The script generated some values by looking at some of the src files and then writes those values to specific locations in other files. The awk code is used to... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

2. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

3. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

4. Shell Programming and Scripting

awk to ignore the text before a particular word

Hi I am new to Awk programming , i would appreciate if anyone help me with the below scenario i have text file arranged in rows and columns like below 11004 04493384 26798 CASSI0000I Server manager initialization started 111004 04493486 26798 CASSI4005I Retrieving ES... (7 Replies)
Discussion started by: rakeshkumar
7 Replies

5. Shell Programming and Scripting

regex - start with a word but ignore that word

Hi Guys. I guess I have a very basic query but stuck with it :( I have a file in which I want to extract particular content. The content is between standard format like : Verify stats A=0 B=12 C=34 TEST Failed Now I want to extract data between "Verify stats" & "TEST Failed" but do... (6 Replies)
Discussion started by: ratneshnagori
6 Replies

6. Shell Programming and Scripting

awk : ignore first 5 line and last line of a file

Hi All, I have text file like as below temp.txt 1 Line temp.txt 2 Line temp.txt 3 Line temp.txt 4 Line temp.txt 5 Line temp.txt 6 Line temp.txt 7 Line temp.txt 8 Line temp.txt N Line I expect the output like as below processing 6 ... processing 7 ... (6 Replies)
Discussion started by: k_manimuthu
6 Replies

7. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

8. Shell Programming and Scripting

Ignore first word using sed in PERL

Please help me in ignoring first word in a line example Input log 123^Babd^Basdf789^B098^Bouiou Desired output abd,asdf789,098,ouiou 123 should be ignored is this possible using sed regular expressions Use code tags - you got a PM with a guide. (2 Replies)
Discussion started by: thankful123
2 Replies

9. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 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