Linux / Unix: sed Command Print Only Matching Lines

in Categories last updated October 19, 2012

I see many examples and man pages on how to do operations like search-and-replace using sed. But, I want to match a given string or a regular pattern expression and display on the screen. How do I print lines with matching pattern using sed command only under Unix like operating systems?

Bash History: Correct / Repeat The Last Command With a Substitution

in Categories , , last updated February 23, 2016

I often type the wrong command as follows under Linux bash shell:

rsync -av dir1


cp -av file1*.txt file2*.txt /path/to/dest

I need to correct those command as follows:

rsync -av dir5
cp -av delta1*.txt delta2*.txt /path/to/dest

How do I replace dir1 with dir5 or file with delta and repeat the last command under bash shell?

HowTo: grep Text Between Two Words in Unix / Linux

in Categories , last updated August 12, 2012

I got over 100s of HTML files in the following format:


my data 1
my data 2
my data 3
my data 10000
my data N times

How do I extract text between two words (<PRE> and </PRE>) in unix or linux using grep command?