SED command

sed – Stream Editor for filtering and transforming text


View text/content between two words:

sed -n "/START-WORD-HERE/,/END-WORD-HERE/p" input-file > output-file

-n : suppress automatic printing of pattern space

p : print the current pattern space


Extract a range of lines from a text file:

sed -n LineNumber1,LineNumber2p filename
Ex: sed -n 155,159p filename > newfile


 

FIND command

Find files between particular date range:

find /path-to-directory -maxdepth 2 -type f -name '*sql.gz' -newermt "2013-03-26 0300" \( -not -newermt "2013-03-31 0310" \) -exec ls -al {} \;

OR
find /path-to-directory -type f -name '*sql.gz' -newermt "4 days ago"  ! -newermt "2 days ago" -exec ls -lrt {} \;
-maxdepth : Maximum level of subdirectories under the ‘/path-to-directory’ that the ‘find’ command can crawl.

-type : Type of the files. ‘f’ is for regular file.

-name : File name.

-newermt : Newer modified time; lower limit of date/time.

! -newermt OR -not -newermt : Upper limit of date/time.

-exec : Executed the command.