Wednesday, May 23, 2012

Finding number of occurrence of a string in a file.

Let's say you have a file (filename: testfile) as shown below and you want to find number of occurrence of a string 'snapshot' in this file.  Please note the specified string could occur more than once in a line. 

"A disk "Snapshot" is a copy of the virtual machine disk file (VMDK) at a certain point in time. It preserves the disk file system,
system memory of your VM by enabling you to revert to the snapshot in case something goes wrong. Snapshot can 
upgrading or patching applications and servers. This article will go over everything you need to know about using snapshot,
including what they are, how they work and advanced techniques. A virtual machine provides several operations for managing
snapshots and snapshot chains. These operations let you create snapshots, revert to any snapshot in the chain, and remove snapshots. You can create extensive snapshot trees."

Command is:  grep -io snapshot testfile | wc -l

No comments:

Post a Comment

Post a Comment