Archive | Awk/Sed/Grep/Find/Regex RSS feed for this section

SED

17 Jul

to produce only thing between two regex’s

cat foo | sed -n '/textarea/,/<\/textarea/p'

Only get from 2nd line to 100th line:

sed -n '2,100p'

grep on Solaris

23 Mar

Solaris doesn’t have recursive grep, instead you have to do something like:

 find . -name *.txt -exec grep  {} /dev/null  \\;

sed – match whitespace

8 Mar

gsed ‘s/^[ \t]*hello/white/g’ # sed uses “[ \t]*” for whitespace

sed – delete following lines

8 Mar

cat | sed ‘/hello/,+d’ # deletes the line

cat | sed ‘/hello/,+3d’ # deletes the line and next 3 lines

awk – previous line

6 Feb

mailq | awk ‘/temporary failure/{print pNR, p0}{pNR=NR;p0=$0}’ | awk ‘{print $2}’ | awk ‘{sub(/*/,””);print $1}’ | /usr/sbin/postsuper -d –

Comparing two files

21 Nov

If you have two files and you want to select lines that exist in one file but not the other, use:

grep -Fxvf fileA fileB

Where fileB contains the superset of fileA

(the -v inverts the search, the -f makes it get search patterns from the file)

Awk – printing previous line

8 Nov

Print a previous line of a match
awk '/findme/{print pNR, p0}{pNR=NR;p0=$0}'