sed -n 5p <file>
- To print a specific line from a file 
sed -n '10,20p' <filename> 
- Prints all the lines between 10 and 20 of a file 
awk 'NR >= 3 && NR <= 6' /path/to/file 
- Prints all lines between two line numbers 
sed -n '3,6p' /path/to/file 
- Prints all lines between two line numbers 
sed '10,20!d' <filename> 
- Prints all the lines between 10 and 20 of a file 
awk 'FNR==5' <file> 
- To print a specific line from a file 
sed '1d' file-name 
-Delete 1
st
 line of a file 
sed '10d' file-name 
-Delete 10
th
 line of a file 
sed '5,10d' <file-name> 
-Delete lines 5 to 10 in a file 
sed '2,$d' filename 
-deletes all lines except the first line in a file which can also be done with sed '1!d' and sed -n  '1p'  filename.  
awk {print $0} <filename> 
-To print all the fields/columns in a file. 
awk {print $3} <filename> 
-To print only the 3
rd
 field/column of a file. 
awk {print $3 $5} <filename> 
-To print the 3
rd
 and 5
th
 fields/columns of a file 
awk F , {print $0} <filename> 
-To print all the fields/columns of a file with , as the separator 
awk F , {print $3} <filename> 
-To print the 3
rd
 field/column of a file with , as the separator 
awk F : {print $5} <filename> 
-To print the 5
th
 field/column of a file with , as the separator 
awk {$3=; print $0} <filename> 
-To print all the fields/columns except the 3
rd
 one of a file. 
awk {$2=$3=; print $0} <filename> 
-To print all the fields/columns except the 2
nd
 and 3
rd
 of a file.  
Deleting the blank lines from a file: 
Using grep: 
grep v ^$ <filename> 
Using sed: 
sed /^$/d <filename> 
Using awk: 
awk /./ <filename> 
awk {print add_to_beginning$0} <filename> Add text at the beginning of each line 
sed s/^/add_to_beginning/ <filename> Add text at the beginning of each line. 
awk {print #$0} <filename>  Comment out all lines 
sed s/^/#/ <filename>  Comment out all lines. 
awk {print $0append_to_end} <filename>    Add text at the end of each line 
sed s/$/append_to_end/ <filename>   Add text at the end of each line  
awk {print $0;} <filename>  Add ; at the end of each line 
awk {print add_to_beginning$0add_to_end} <filename>   Add text at the beginning and end 
of each line. 
sed s/.*/add_to_beginning&add_to_end/ <filename>  Add text at the beginning and end of 
each line.  
SQL Joins: 
  INNER JOIN: Returns all rows when there is at least one match in BOTH tables 
  LEFT JOIN: Return all rows from the left table, and the matched rows from the right table 
  RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table 
  FULL JOIN: Return all rows when there is a match in ONE of the tables. 
SQL Constraints: 
  NOT NULL - Indicates that a column cannot store NULL value 
  UNIQUE - Ensures that each row for a column must have a unique value 
  PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Ensures that a column (or 
combination of two or more columns) have an unique identity which helps to find a 
particular record in a table more easily and quickly 
  FOREIGN KEY - Ensure the referential integrity of the data in one table to match values in 
another table 
  CHECK - Ensures that the value in a column meets a specific condition 
  DEFAULT - Specifies a default value when specified none for this column. 
PRIMARY KEY Constraints: 
1.  The PRIMARY KEY constraint uniquely identifies each record in a database table. 
2.  Primary keys must contain unique values. 
3.  A primary key column cannot contain NULL values. 
4.  Each table should have a primary key, and each table can have only ONE primary key. 
VIEWS: 
  A view is a virtual table. 
CREATE VIEW Statement: 
1.  In SQL, a view is a virtual table based on the result-set of an SQL statement. 
2.  A view contains rows and columns, just like a real table. The fields in a view are fields from 
one or more real tables in the database. 
SQL CREATE VIEW Syntax: 
CREATE VIEW view_name AS 
SELECT column_name(s) 
FROM table_name 
WHERE condition  
SQL Updating a View: 
You can update a view by using the following syntax: 
SQL CREATE OR REPLACE VIEW Syntax: 
CREATE OR REPLACE VIEW view_name AS 
SELECT column_name(s) 
FROM table_name 
WHERE condition  
SQL Dropping a View: 
You can delete a view with the DROP VIEW command. 
DROP VIEW view_name. 
SQL Aggregate Functions: 
SQL aggregate functions return a single value, calculated from values in a column. 
Useful aggregate functions: 
  AVG() - Returns the average value 
  COUNT() - Returns the number of rows 
  FIRST() - Returns the first value 
  LAST() - Returns the last value 
  MAX() - Returns the largest value 
  MIN() - Returns the smallest value 
  SUM() - Returns the sum 
SQL Scalar functions: 
SQL scalar functions return a single value, based on the input value. 
Useful scalar functions: 
  UCASE() - Converts a field to upper case 
  LCASE() - Converts a field to lower case 
  MID() - Extract characters from a text field 
  LEN() - Returns the length of a text field 
  ROUND() - Rounds a numeric field to the number of decimals specified 
  NOW() - Returns the current system date and time 
  FORMAT() - Formats how a field is to be displayed.