Unix commands: The best tool for the job
With Unix, there are always many ways to do a single thing, but sometimes one approach is just a lot better! Let's look at a couple examples of commands that are right for the job.
View full article »
Esther Schindler
If the comments are ugly, the code is ugly
claird
SVG a graphics format for 21st century
pasmith
Take Chrome OS for a test spin
Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?
jfruh
Android fragments vs. the iPhone monolith
mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive
Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325
Join the conversation here
Quick, practical advice for IT pros. Made fresh daily.
Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.













The Best Tool For The Job
In your example you state:> If you need to count how many times a particular string
> appears in a file . . .
but actually neither of your examples answers the question
exactly as lines can contain multiple occurrences of the
same string. Your example only shows the number of lines
that contain the string, not the number of strings. This
is a much more complex problem. I have not found a simple
command to do this, but I have written a small script to
do so. It is not very elegant, but here it is:
---
#!/bin/ksh
integer count=0
echo $count
count=`grep -c "$1" "$2"`
cp $2 $2.$$
while
grep "$1" $2.$$ > /dev/null 2>&1
do
ed - $2.$$ <<-EOF
g/$1/s///
w
q
EOF
count=$count+`grep -c "$1" "$2.$$"`
done
rm $2.$$
echo $count
---
This works on my SUN Solaris 10 system.