Tag Archive for grep

SHELL SCRIPT PARSING LOGFILE

#!/bin/bash
 
#initialize temp files
echo "" > topimages.txt
echo "" > images.txt
echo "" > unique.txt
echo "" > all.txt
 
if [ "$1" = "" ]; then
        echo -e "normally use like this:"
        echo -e "	./getTopPages.sh $1"
        echo -e "	get all jpg's -- ./getTopPages.sh jpg"
        echo -e "	get everything in photos -- ./getTopPages.sh photos"
        echo -e "*****" 
        exit
fi 
 
#live server logfile
logfile=/var/log/httpd/...
 
grep $1 $logfile| awk '{print $7}' | sort > all.txt
echo found: $(grep '^.*$' all.txt -c) images total...
 
grep $1 $logfile| awk '{print $7}' | sort | uniq > unique.txt
echo found: $(grep '^.*$' unique.txt -c) unique images...
 
echo '<images>' > images.txt
 
        for i in $( grep '^.*$' unique.txt  ); do
 
                        cnt=$( grep $i all.txt -c )
 
                        #add leading zeros
                        if test $cnt -lt 10; then
                                 lzcnt=0000$cnt
                        elif test $cnt -lt 100; then
                                 lzcnt=000$cnt
                        elif test $cnt -lt 1000; then
                                 lzcnt=00$cnt
                        elif test $cnt -lt 10000; then
                                 lzcnt=0$cnt
                        elif test $cnt -lt 100000; then
                                 lzcnt=$cnt
                        else
                            	 lzcnt=$cnt
                        fi
 
                        echo '<image count="'$lzcnt'" src="'$i'" />' >> images.txt
 
        done
 
sort images.txt -r -k17 > topimages.xml
echo '</images>' >> topimages.xml
 
echo removing temp files...
 
rm images.txt
rm unique.txt
rm all.txt
rm topimages.txt

source

Howto list all the file extension types in an SVN log dump

svn log -v > myrepo.log

perl -ne 'print qq{$1
} if m{^s+.*(.[^.s]w+)$}' myrepo.log | sort | uniq -c | sort -r

source

Recursive grep string search

grep -Rin "search string here" *

source

Find a specific string in files of a certain type

find / -name "*.js" -exec grep -Hn H3qqea3ur6p {} ;

source

Search BASH history w/ grep

history | grep 'ls'

source

Grep for files that do not match a pattern

grep -L "the pattern" *

# to recurse into subdirectories

grep -RL "the pattern" *

source

Linux Command for Listing all files which contains the word ‘abc’

find / -type f -exec grep -H 'abc' {} ;

source

grep string in file type

## To find by file type in this case, .e and .pl files
## replace <string> with desired string to grep for...
find . | egrep -i ".(e|pl)" | xargs grep <string>

source

grep string in file type

## To find by file type in this case, .e and .pl files
## replace <string> with desired string to grep for...
find . | egrep -i ".(e|pl)" | xargs grep <string>

source

Figure out your Internal / External Ip Address using Terminal

#1. Use ifconfig and pipe ( | ) it into grep which will search for the 'inet' field
#2. Pipe the data once again into grep and reverse the logic of the search (-v) to remove 12.7.0.0.1.  Using -v will match all the lines that do not match 127.0.0.1 (aka loopback)
#3. Use Cut to show the second field in the line, using spaces as a delimiter

ifconfig | grep 'inet ' | grep -v 127.0.0.1 | cut -d   -f2

source