bashconsole.org

Linux commands => 1. General Commands => Topic started by: bashconsole on May 10, 2009, 02:59:42 PM



Title: grep, egrep, fgrep
Post by: bashconsole on May 10, 2009, 02:59:42 PM
NAME
       grep, egrep, fgrep - print lines matching a pattern

SYNOPSIS
       grep [options] PATTERN [FILE...]
       grep [options] [-e PATTERN | -f FILE] [FILE...]

DESCRIPTION
       Grep  searches  the  named  input  FILEs (or standard input if no files are named, or the file name - is
       given) for lines containing a match to the given PATTERN.  By default, grep prints the matching lines.

       In addition, two variant programs egrep and fgrep are available.  Egrep is the same as  grep -E.   Fgrep
       is the same as grep -F.

http://bashconsole.org/man.1.grep


Title: Re: grep, egrep, fgrep
Post by: bashconsole on May 10, 2009, 03:05:56 PM
Excludes new emails according to exclude-list. Input file format: one email per line. Output: new unique emails are in *.csv file.
Code:
#!/bin/bash

echo "Joining..."
cat EXCLUDE-LIST $1 > 1
echo "Sorting..."
cat 1 |sort|uniq > 2
echo "Excluding new records..."
diff EXCLUDE-LIST 2 > 3
cat 3 |egrep -e '\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.\w{2,6}' > 4
replace "> " "" -- 4
echo "Preparing results..."
mv 2 EXCLUDE-LIST
mv 4 $1.cvs
rm 1 3