How to find a particular word from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to find a particular word from a file
# 1  
Old 10-10-2011
How to find a particular word from a file

Hello Experts,

I have to count the word like "RESULT_CODE: : -6" from the multiple files names like req.result_2_vqx-71144750.log for a particular date. Lets suppose the date is 10 OCT 2011.

How I can do it with a single command in Solaris environment.


Reagrds
Oracle User
# 2  
Old 10-10-2011
Code:
perl -MPOSIX -e'
  ($dt, $patt, $logs) = @ARGV;
  $dt eq strftime("%Y-%m-%d", localtime +(stat)[9]) and
    print $_, " ==> ", qx/grep -c "$patt" $_/ 
    for glob "$logs";
    ' '2011-10-10' 'RESULT_CODE: : -6' 'req.result*.log'

# 3  
Old 11-09-2011
This command is not working. Is there any other way to do this.


Regards
Oracle User
# 4  
Old 11-09-2011
"This command is not working" is a useless answer for anybody who tries to help you. Show some effort and supply at least an error message.
# 5  
Old 11-09-2011
How does the date fit in? Do you have some example input?
# 6  
Old 11-09-2011
I have not written that the solution given is "the useless one", in my post anywhere.

Also there is no error message displayed for the above command. my only intention was to know the exact command ...thats all !!

How do you know that I have not tried enough on this problem...instead of writing a long essay for a particular forumn. please metion the solution if you know. This will save your time as well as mine.

Regards
Oracle User

---------- Post updated at 10:50 PM ---------- Previous update was at 10:45 PM ----------

@CarloM,
Here is the file, for Nov 7
Code:
-rw-rw-r--   1 oracle   dba          962 Nov  7 14:54 req.267891147-67891246.log

There are lots of logs for this particular date; lets say between 500-1000 logs. I need a command which filter a particular word from all the logs and give the count as a result.

Regards
Oracle User

Moderator's Comments:
Mod Comment Please use code tags <- click the link!

Last edited by zaxxon; 11-09-2011 at 10:28 AM.. Reason: code tags, see PM
# 7  
Old 11-09-2011
Quote:
Originally Posted by Oracle_User
I have not written that the solution given is "the useless one", in my post anywhere.

Also there is no error message displayed for the above command. my only intention was to know the exact command ...thats all !!

How do you know that I have not tried enough on this problem...instead of writing a long essay for a particular forumn. please metion the solution if you know. This will save your time as well as mine.

Regards
Oracle User
As you notice, this doesn't help us a lot to save our time too...
Better is to post some lines of your log file and the desired output.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to find biggest word in a file....?

With any cmd like sed grep ask etc... (1 Reply)
Discussion started by: sidpatil
1 Replies

2. UNIX for Dummies Questions & Answers

Find word in a large file

Hi all I am working on disallowing users to use easy passwords in pam.d setting on RHEL 5.7 and SuSe 11, and I was hoping to add more words into the current cracklib dict, so I use "echo" command to append new words into the file I dont want to add the same words into the dict, I think I... (2 Replies)
Discussion started by: hedkandi
2 Replies

3. 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

4. Shell Programming and Scripting

Find word in file then get following characters

Hello, I have several xml files from which I want to find and return a particular string I want to locate the InId="00000008". Now that is inlcuded within a tag and ofcourse the number is different every time this is what I came up with given that after greping the line that contains the... (6 Replies)
Discussion started by: TasosARISFC
6 Replies

5. UNIX for Dummies Questions & Answers

find a word in a file, plus the next 6 characters?

I plan to use sed in a script to replace a string. My problem is the last 6 characters of the word to be replaced can be different each time, plus it's not always in the same spot on the line so I can't use cut or nawk to get the field. So I am looking for a way to find a certain word in a file,... (6 Replies)
Discussion started by: mikayla73
6 Replies

6. Shell Programming and Scripting

Find a word in input file

Hi, I had a input file containing, abcdefghij;20100903040607;1234567891;GLOBAL; abc123;20100903040607;12345;09;thestdf; def456;20100903040607;67891;04;bnkim; I need to search word GLOBAL in my file. If it is found then do something else do other thing How can i write if loop for... (13 Replies)
Discussion started by: Poonamol
13 Replies

7. 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

8. Shell Programming and Scripting

How to find a count of a word within a file

Hello, I'm looking for a wait to count the number of occurrences of a certain string of characters within a file. The file that I trying to parce has segments within the file that have a header and footer to each segment and I'm trying to do a count of the header string and compare it to a count... (9 Replies)
Discussion started by: bd_joy
9 Replies

9. Shell Programming and Scripting

find a word in a file, and change a word beneath it ??

Hi all, I have a file with lines written somewhat like this. aaaa ccc aa linux browse = no xssxw cdcedc dcsdcd csdw police dwed dwd browse = no cdecec (2 Replies)
Discussion started by: vikas027
2 Replies

10. UNIX for Dummies Questions & Answers

how to find a word repeated in a file

Hi everyone, I have a file in which a word is repeated more than one time and I want to know how many times it is repeated. ex: if i repeated word 'guru' in 10 lines I can get the o/p as: cat filename | grep -c 'guru'. How ever if the word is repeated more than one time, then how can I... (4 Replies)
Discussion started by: gurukottur
4 Replies
Login or Register to Ask a Question