In order to keep bashrc or bash_profile clean, aliases should go in the bash_aliases
file. Add below IF to bashrc.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Then add aliases to bash_aliases:
alias my_alias='whatever command here'
Custom bash functions:
function_name () {
command1
command2
}
As an example I had built this to sort a csv file without sorting the header:
# funtion_name starting_row input_file output_file
sort_csv(){
start_row=$1
last_row=$1
input_file=$2
output_file=$3
let "last_row -= 1"
#echo $start_row
#echo $last_row
head -n $last_row $input_file > $output_file && tail -n $start_row $input_file | sort -k 1 >> $output_file
}
sort_csv 6 sample.csv sorted.csv