Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-10 of 14 total  RSS 

LoadRunner grep statements for errors

grep -rnE "Error|Warning|error|warning" * | grep \.html  | grep "<TITLE>Error"

grep -rnEA10 "Error|Warning|error|warning" * | grep \.html  | grep -E "<b>"

grep -rnEA200 "0\-0" * | grep \.html | grep -E "advertiserId"

Count line of code

// Use wc to count lines


#!/bin/bash

check out goes here
cd dir
grep -r "*;*" * | wc -l

extract table names from sql log file

grep "from " /var/log/mysql/mysqld.log | awk -Ffrom '{print $2}' | awk '{print $1}' | cat > /home/shantanu/testing.txt

Parse Exim log file with SpamAssassin score

grep '\[Spam score: [1-9]' /var/log/exim/main.log | awk '{print $3}' | xargs -t -i grep {} /var/log/exim/main.log > /var/log/exim/spam_score.log


grep 'reporter\.pl' /var/log/exim/main.log | awk '{print $3}' | xargs -t -i grep {} /var/log/exim/main.log > /var/log/exim/spam_reporter.pl.log

email addresses using egrep

// email addresses

egrep "\w+([._-]\w)*@\w+([._-]\w)*\.\w{2,4}"

unix wizards of the realm:

// SVN ignore based on .cvsignore file:

svn propset svn:ignore -F .cvsignore .


// grep:
with line number: -nwith file name: -H


// os x housekeeping:


// install perl module:
sudo perl -MCPAN -e 'install Bundle::LWP'


// meta refresh (i have never typed this line start to finish in my life. i have probably copy-pasted it 7,000 times
<meta http-equiv=Refresh content="0; URL=http://blog.jm3.net/" />


// get files off codeswami:
ssh -l cs 208.101.26.91


// SQL tricks:
http://jm3.net/cgi-bin/safe/wiki.pl?MySqlLibrary

Twitter bot weatherlisbon

This little bash script shows how to use curl, grep, tail, sed and perl one-liners in order to compose a bleeding-edge twitter bot.
This one returns daily weather forecasts for Lisbon city based on the BBC weather forecast rss feed.

#! /bin/sh

#Goto here
here=/home/guillaume/Personal
cd $here

#BBC Lisbon weather id
id=0048

#BBC weather RSS feed address
feed="http://feeds.bbc.co.uk/weather/feeds/rss/5day/world/${id}.xml"

#City
city=lisbon

#temporary file
file="weather${city}"

#Weather twitter bot
twitbot=weatherlisbon:*******

#Timestamp the log file
echo .>> $file.log
date >> $file.log

#Read the RSS feed and filter it
curl $feed | grep 'title' | tail -n 1 | perl -wlne'm/title>(.*)<\/title/i && print $1' | sed -e "s/&#xB0;//g" > $file.txt

#Read the forecast into a weather variable
read weather < $file.txt

#Twit the weather variable away
curl --basic --user $twitbot --data status="$weather" http://twitter.com/statuses/update.xml >> $file.log

grep for a file, excluding svn metadata directories and files

Grep for something, excluding the annoying svn metadata (.svn**)
The find piece could also be used for more general tasks -- just remove the pipe and take a look at the output to see if it will work for you.
I tried (and failed) to use the find to a path preserving copy from within a subdirectory in a checkout...though there must be a way.

find . -path '*/.svn' -prune -o -type f -print | xargs -e grep -I -n -e PATTERN

Find and replace

This will search all files recursively for SEARCH_STRING and replace all occurrences of SEARCH_STRING with REPLACE_STRING throughout each unique file found. It also creates a backup of each modified file so that FILE is backed-up as FILE~ (with a tilde).

grep -R --files-with-matches 'SEARCH_STRING' . | sort | uniq | xargs perl -pi~ -e 's/SEARCH_STRING/REPLACE_STRING/'

search with grep in linux


Searching files

grep (r - recursive, s - no messages, n -line number, i - case insensitve, H -with filename)
grep -rsniH your_string

match lines containing the string "I am a cat" or the string "I am a dog".
grep "I am a \(cat\|dog\)" 


Search application

to find PID (process ID) of a certain application or process,
pgrep


find application port
netstat -a | grep ftp

« Newer Snippets
Older Snippets »
Showing 1-10 of 14 total  RSS