Grep and count the string in a file.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep and count the string in a file.
# 1  
Old 06-02-2009
Power Grep and count the string in a file.

Hi,

I have to grep a word 'XYZ' from 900 files ( from 2007 till date), take its count month wise. The output should display month, count , word 'XYZ' .
I tried searching the forum for solution but could find any.
I would apprieciate if any one can help me asap ....

Many ThanksSmilie
# 2  
Old 06-02-2009
Can you show what you have tried so far?
# 3  
Old 06-02-2009
can anyone help please ....SmilieSmilie

Last edited by vikram2008; 06-02-2009 at 08:12 AM..
# 4  
Old 06-02-2009
Quote:
Originally Posted by vikram2008
can anyone help please ....SmilieSmilie
check the man page of grep. don't be lazy
# 5  
Old 06-02-2009
I appreciate your response ...Smilie

I am not lazy bro Smilie..i am searching whatever i can .. i temporarly got what i want but i want get it done through proper script ..
right now i have used

cat /path/*filename* |grep 200810 |grep XYZ |wc -l Smilie

but its not getting the compressed files count and i have to maunaly copy this date in notepad..

if i could get the count, month from a single command line it would be great ...
# 6  
Old 06-02-2009
Quote:
Originally Posted by vikram2008
I appreciate your response ...Smilie

I am not lazy bro Smilie..i am searching whatever i can .. i temporarly got what i want but i want get it done through proper script ..
right now i have used

cat /path/*filename* |grep 200810 |grep XYZ |wc -l Smilie

but its not getting the compressed files count and i have to maunaly copy this date in notepad..

if i could get the count, month from a single command line it would be great ...

Heyo,
how about structure of your files? Maybe, if it isn't so secret, just a little pattern of few lines to copy-paste here, so I can better see what you mean ynd try it on my machine. If you mean to number lines then try grep -n, if something else - I need more info on the subject.
# 7  
Old 06-02-2009
Smilie contents of the file is like below... there are thousands of such records in a file. it may be value for Order_Type can be either XYZ or ABC...i get these file daily .. Thanks mate for responding Smilie

<ORDER Date_Format="YYYYMMDDHH24MISS" Line_Ref="4444455" Action_Date="20090309000000"><CUSTOMER_INFO Customer_Ref="423555577" Job_No="3051908"/> <PRODUCT_INFO Type="WC"/><WC Billing_Destination="CM" Order_Type="XYZ" Main_CLI="544444444444"/></ORDER>
</ORDERS>

<ORDER Date_Format="YYYYMMDDHH24MISS" Line_Ref="4667455" Action_Date="20090309000000"><CUSTOMER_INFO Customer_Ref="234442357" Job_No="2055688"/> <PRODUCT_INFO Type="WC"/><WC Billing_Destination="CM" Order_Type="XYZ" Main_CLI="99844444444"/></ORDER>
</ORDERS>
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

2. UNIX for Beginners Questions & Answers

Grep pattern file and count occurances

Guys I am trying grep to read from pattern file and count occurances of each word. input is firstplace secondplace secondpot patternfile is place first second i want the following. 1-count number of times keywords in patternfile occurs in begining of each line in input file. so... (12 Replies)
Discussion started by: ahfze
12 Replies

3. Shell Programming and Scripting

Grep a string and count following lines starting with another string

I have a large dataset with following structure; C 0001 Carbon D SAR001 methane D SAR002 ethane D SAR003 propane D SAR004 butane D SAR005 pentane C 0002 Hydrogen C 0003 Nitrogen C 0004 Oxygen D SAR011 ozone D SAR012 super oxide C 0005 Sulphur D SAR013... (3 Replies)
Discussion started by: Syeda Sumayya
3 Replies

4. Shell Programming and Scripting

Grep string in files and list file names that contain the string

Hi, I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat. My OS is: SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies

5. Shell Programming and Scripting

Recursive find / grep within a file / count of a string

Hi All, This is the first time I have posted to this forum so please bear with me. Thanks also advance for any help or guidance. For a project I need to do the following. 1. There are multiple files in multiple locations so I need to find them and the location. So I had planned to use... (9 Replies)
Discussion started by: Charlie6742
9 Replies

6. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

7. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

8. Shell Programming and Scripting

Grep string from logs of last 1 hour on files of 2 different servers and calculate count

Hi, I am trying to grep a particular string from the files of 2 different servers without copying and calculate the total count of its occurence on both files. File structure is same on both servers and for reference as follows: 27-Aug-2010... (4 Replies)
Discussion started by: poweroflinux
4 Replies

9. Shell Programming and Scripting

Parse file from remote server to calculate count of string existence in that file

Hi I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files. Say a file abc.log exist on 2 servers. I want to search for string "test" on both files and calculate the total count of search string's existence. For... (6 Replies)
Discussion started by: poweroflinux
6 Replies

10. Shell Programming and Scripting

grep and count no of occurences in every line of a file

Hi Folks, I have a input file of the below format. ~~~OLKIT~OLKIT~1~~TBD~BEST PAGER & WIRELESS~4899 COMMON MARKET PLACE~~~DUBLIN~KS~43016~I~Y~DIRECT~D~~0 BPGRWRLS~~~OLKIT~OLKIT~1~~TBD~BEST PAGER & WIRELESS~4899 COMMON MARKET PLACE~~~DUBLIN~KS~43016~I~Y~DIRECT~D~~0... (12 Replies)
Discussion started by: srikanthgr1
12 Replies
Login or Register to Ask a Question