<commit_before>Bash


grep                                                          Search for a string
grep -i                                                       Search for a string and ignore the case
grep -r                                                       Search recursively for a string in a directory
zgrep                                                         Search for a string in a zip file
grep -v                                                       Exclude a string from a file
egrep -v '(FOO|BAR)'                                          Exclude multiple strings from a file

cut -d ' ' -f2                                                Cut with a delimiter of a space, then print the second field
cut -d ' ' -f2-5                                              Cut with a delimiter of a space, then print the second through the fifth fields
cut -d ' ' -f2-                                               Cut with a delimiter of a space, then print the second field to the end

awk '{print $NF}'                                             Print the last column
awk '{print $2}'                                              Print the second column
awk '{print $2,$5}'                                           Print the second and fifth columns
awk -F "https://" '{print $2}'                                Use a string as a delimiter, then print the second column

head                                                          Print the first 10 lines
head -5                                                       Print the first 5 lines
tail                                                          Print the last 10 lines
tail -5                                                       Print the last 5 lines
tail -f                                                       Print the contents of a file as it grows

sort                                                          Sort a file
sort -u                                                       Sort a file and show only unique values

wc -l                                                         Count the number of lines
wc -m                                                         Count the number of characters

comm file1 file2                                              file1, file2, shared by both files
comm -<123> file1 file2                                       Used to supress columns
comm -12 file1 file2                                          Supress columns 1 and 2
diff -<c or u> file1 file2
vimdiff file1 file2
------------------------------------------------------------------------------------------------------------------------------------------------------

sed 's/^/FOO/g'                                               Add FOO to the beginning of each line
sed 's/$/FOO/g'                                               Add FOO to the end of each line

column -t                                                     Align columns

sed /^$/d                                                     Compress blank lines
paste -s -d" "                                                Convert a list into a single line

apt-get install xml-twig-tools
xml_grep ‘firstName' file.xml --text_only                     Extract data from XML element

grep -oe '[a-zA-Z0-9._]\+@[a-zA-Z]\+.[a-zA-Z]\+'              Find emails
grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b'                    Find IPs
grep -E '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b'                     Find lines that contain an IP

perl -pe 's/\d{2}\/\d{2}\/\d{2}//g'                           Find dates mm/dd/yy

sed '/[[:blank:]]/d'                                          Find lines that contain a single word
grep 'FOO'                                                    Find FOO
sed '/FOO/I,+12 d'                                            Find FOO, and delete that and the next 12 lines
sed 's/FOO.*$//g'                                             Find FOO, and delete to the end of file
sed 's/FOO/\n&/g'                                             Find FOO, and insert a new line and FOO
grep 'FOO\|BAR'                                               Find FOO, and lines that contain BAR
sed '1N;N;/\(.*\n\)\{2\}.*FOO/P;$d;D'                         Find FOO, and print the second line before that
awk -v n=-2 'NR==n+1 && !NF{next} /FOO/ {n=NR}1'              Find FOO, if the next line is blank, delete it

awk -v n=-2 'NR==n+1 && !NF{next} /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/ {n=NR}1'
                                                              Find lines that start with IP, if the next line is blank, delete it

awk -v n=-2 'NR==n+1 && NF{print hold} /FOO/ {n=NR;hold=$0;next}1'
                                                              Find FOO, if the next line is blank, delete line containing FOO

awk '/FOO/ { FOO = 1; next }  FOO == 1 && /^$/ { FOO = 0; next }  { FOO = 0 }  { print }'
                                                              Find FOO, if the next line is blank, delete both lines

awk -v n=-2 'NR==n+1 {if($0 ~ /BAR/) { next; } else { print hold } } /FOO/ {n=NR;hold=$0;next}1'
                                                              Find FOO, if the next line contains BAR, delete both lines

sed 's/.* //'                                                 Find lines that contin a space and print from the space to the end of the line
grep -E 'FOO|BAR'                                             Find lines that contain FOO or BAR
grep '[0-9]'                                                  Find lines that contain a number
grep '[0-9]$'                                                 Find lines that end with a number
grep 'FOO$'                                                   Find lines that end with FOO
sed 's/FOO$//'                                                Find lines that end with FOO, and delete FOO

grep '^[0-9]'                                                 Find lines that start with a number
grep '^FOO'                                                   Find lines that start with FOO
sed '/^FOO/{n;d;}'                                            Find lines that start with FOO, and delete the following line
printf '%s\n' 'g/^FOO/-1d' w | ed -s                          Find lines that start with FOO, and delete the previous line
sed '/^FOO/i\ '                                               Find lines that start with FOO, and insert a line before
sed '/^FOO/a\ '                                               Find lines that start with FOO, and insert a line after
sed -e :a -e '$!N;s/\nFOO/ /;ta' -e 'P;D'                     Find lines that start with FOO, insert a space and append to the previous line

fmt -w 25                                                     Limit the number of characters on a line to 25

sed -n '/FOO/,$p'                                             Print from FOO to the end of the file
sed s/FOO.*//                                                 Print from FOO to the end of the line
sed -n '5,/^$/p'                                              Print from the 5th line to the first blank line
awk 'NR == 1 || NR % 3 == 0'                                  Print the first and every third line
awk 'NR % 3 == 0'                                             Print every third line
sed -n '/FOO/,/BAR/p'                                         Print lines between FOO and BAR
sed -e '/./{H;$!d;}' -e 'x;/FOO/!d;'                          Print paragraphs that contains FOO
awk '{print $2 " " $1}'                                       Print the second column, insert a space, then the first column

find . -type f -empty -exec rm "{}" \;                        Remove all empty files
sed 's/[A-Z]\{2\},//g'                                        Remove any 2 capital letters followed by a comma
sed '/^$/d'                                                   Remove blank lines
sed 's/[0-9]\{2\}\/[0-9]\{2\}\/[0-9]\{2\}//g'                 Remove dates (mm/dd/yy)
cat -s                                                        Remove double spacing
sed 's/^....//'                                               Remove first 4 characters from each line
sed '1,5d'                                                    Remove first 5 lines
sed 's/^[ \t]*//; s/[ \t]*$//'                                Remove leading and trailing whitespace from each line
sed 's/^[ \t]*//'                                             Remove leading whitespace from each line
sed '/FOO/,/BAR/d'                                            Remove lines between FOO and BAR
awk '/FOO/{f=1} (!f || f>2){print} (f && /BAR/){f++}'         Remove lines from FOO and the second BAR
awk '$2 !~ /[a-z]/'                                           Remove lines that contain [a-z] in the second column
sed '/[[:blank:]]/!d'                                         Remove lines that contain a single word
awk 'NF != 2'                                                 Remove lines that contain two words
awk '!(/FOO/ && /BAR/)'                                       Remove lines that contain FOO and BAR
printf '%s\n' 'g/FOO/d\' '-d' w | ed -s                       Remove lines that contain FOO and the previous line
sed '/@.*@/d'                                                 Remove lines that contain two @ symbols
sed '/[0-9]/d'                                                Remove lines that contain a number
sed '/[0-9]$/d'                                               Remove lines that end with a number
sed '/FOO$/d'                                                 Remove lines that end with FOO
sed '/^[0-9]/d'                                               Remove lines that start with a number
sed '/^FOO/d'                                                 Remove lines that start with FOO
grep -Ev '^\b([0-9]{1,3}\.){3}[0-9]{1,3}\b'                   Remove lines that start with an IP
sed '/^.,/d'                                                  Remove lines where the second letter is a comma
cat tmp | tr -d "\n" | tr -d " "                              Remove new lines and spaces. Ex copying a hash from Rubeus for use in Mimikatz
cat tmp | rev | sed 's/^[ \t]*//' | cut -d ' ' -f2- | rev     Remove the last column
head -n -5                                                    Remove the last 5 lines
sed 's/[ \t]*$//'                                             Remove trailing whitespace from each line

sed 's/ \{2,\}/,/g'                                           Replace 2 or more spaces with a comma
sed 's/\.\.\.//g'                                             Replace 3 periods with nothing
sed 's/FOO/BAR/g'                                             Replace FOO with BAR
find . -type f -exec sed -i 's/FOO/BAR/g' {} +                Replace FOO with BAR recursively in the current directory
sed '/TEST/!s/FOO/BAR/g'                                      Replace FOO with BAR, except on lines that contain TEST
sed '/TEST/s/FOO/BAR/g'                                       Replace FOO with BAR, on lines that contain TEST
sed 's/FOO//g'                                                Replace FOO with nothing
sed -n 'H; ${x; s/\n/|/g; p}'                                 Replace 'new line' with a pipe '|'
cat tmp | tr ';' '\n'                                         Replace semicolon with a new line
sed 's/\([^,]*,\)\{7\}[^,]*,/&\n/g'                           Replace the 8th comma with a new line

sort -k2                                                      Sort by the second column
sort -n -u -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4                   Sort IPs

sed 's/[^ ]\+/\L\u&/g'                                        Title case

tr -d '\t'                                                    Delete a tab
tr ',' '\n'                                                   Translate a comma to a new line
tr -s ' '                                                     Translate any number of spaces to a single space
tr '[a-z]' '[A-Z]'                                            Translate lower case to upper case
tr '[A-Z]' '[a-z]'                                            Translate upper case to lower case

sed "s/$FOO./$FOO/g"                                          Variables - use double quotes with sed or grep
------------------------------------------------------------------------------------------------------------------------------------------------------

# Check for argument. If not given, print the usage
if [ -z "$1" ]; then
     echo "Usage: $0 <domain name>"
     exit
fi

# Chech for argument. Give feedback to user
echo -e "Usage: ./test.sh <target IP> <scan type>"
if [ "$2" == "All" ]; then
     echo "Running all scans on $1."
else
     echo "Running a $2 scan on $1."
fi

# Check for root
if [[ $EUID -ne 0 ]]; then
     echo
     echo "[!] This script must be ran as root."
     exit
fi

# Check for no answer
if [ -z $location ]; then
     f_Error
fi

# Check for wrong answer
if [ ! -f $location ]; then
     f_Error
fi

# Check for two variables
echo -n "Enter color: "
read color
echo -n "Enter another color: "
read color2

if [ $color = "red" ] && [ $color2 = "grey" ]; then
     echo
     echo "The Wall won't fall."
     echo
     exit
else
     echo
     echo "Those colors are crap."
     echo
fi

# Validate input is a number and that it is greather than 0
if ! [[ "$number" =~ ^[0-9]+$ ]] || [[ "$number" -le "0" ]]; then
     f_error
fi

# Check for valid port number
if [[ $port -lt 1 || $port -gt 65535 ]]; then
     echo "Invalid port."
     exit
fi
------------------------------------------------------------------------------------------------------------------------------------------------------

# Colors

RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
BLUE='\033[1;34m'
NC='\033[0m'

echo -e "I ${RED}love${NC} Discover."
------------------------------------------------------------------------------------------------------------------------------------------------------

# Compare two dates

date1=$(date +"%s")
date2=$(date +"%s")
diff=$(($date2-$date1))
echo "$(($diff / 60)) min and $(($diff % 60)) sec."
------------------------------------------------------------------------------------------------------------------------------------------------------

# Files and folders

if [ -e test ]; then
     echo "This file exists."
fi

if [ ! -e test ]; then
     echo "This file does not exist."
fi

if [ ! -s test ]; then 
     echo "This file is empty."
fi

if [ -d test ]; then
     echo "This folder exists."
fi

if [ ! -d test ]; then
     echo "The folder does not exist."
fi
------------------------------------------------------------------------------------------------------------------------------------------------------

# If a process is running, kill it

pid=$(ps -ef | grep 'discover.sh' | grep -v 'grep' | awk '{print $2}')

if [ -n "$pid" ]; then
     kill -9 $pid
fi
------------------------------------------------------------------------------------------------------------------------------------------------------

# Read in a file and do something

for i in $(cat subdomains); do
     host $i | grep 'has address' | cut -d ' ' -f4
done

while read i; do
     host $i | grep 'has address' | cut -d ' ' -f4
done < subdomains
------------------------------------------------------------------------------------------------------------------------------------------------------

# Special characters to escape

~|`|!|@|#|\$|%|\^|&|\*|\(|\)|_|-|\+|=|{|\[|}|]|\|:|;|"|<|,|>|\.|\?|/|
------------------------------------------------------------------------------------------------------------------------------------------------------

# Use a variable and set a constant

if [ "$payload" == "1" ]; then
     format="raw"
     platform="android"
else
     format="exe"
     platform="windows"
fi
------------------------------------------------------------------------------------------------------------------------------------------------------

# xterm

Open an xterm window in the center of the screen, run a command, and stay open
xterm -hold -bg blue -fg white -geometry 90x10 -T "Test ping" -e ping -c3 google.com

Open an xterm window in the top right corner of the screen, run a command, and stay open
xterm -hold -bg blue -fg white -geometry 90x10-0+0 -T "Test ping" -e ping -c3 google.com
<commit_msg>Added a sed one liner.<commit_after>Bash


grep                                                          Search for a string
grep -i                                                       Search for a string and ignore the case
grep -r                                                       Search recursively for a string in a directory
zgrep                                                         Search for a string in a zip file
grep -v                                                       Exclude a string from a file
egrep -v '(FOO|BAR)'                                          Exclude multiple strings from a file

cut -d ' ' -f2                                                Cut with a delimiter of a space, then print the second field
cut -d ' ' -f2-5                                              Cut with a delimiter of a space, then print the second through the fifth fields
cut -d ' ' -f2-                                               Cut with a delimiter of a space, then print the second field to the end

awk '{print $NF}'                                             Print the last column
awk '{print $2}'                                              Print the second column
awk '{print $2,$5}'                                           Print the second and fifth columns
awk -F "https://" '{print $2}'                                Use a string as a delimiter, then print the second column

head                                                          Print the first 10 lines
head -5                                                       Print the first 5 lines
tail                                                          Print the last 10 lines
tail -5                                                       Print the last 5 lines
tail -f                                                       Print the contents of a file as it grows

sort                                                          Sort a file
sort -u                                                       Sort a file and show only unique values

wc -l                                                         Count the number of lines
wc -m                                                         Count the number of characters

comm file1 file2                                              file1, file2, shared by both files
comm -<123> file1 file2                                       Used to supress columns
comm -12 file1 file2                                          Supress columns 1 and 2
diff -<c or u> file1 file2
vimdiff file1 file2
------------------------------------------------------------------------------------------------------------------------------------------------------

sed 's/^/FOO/g'                                               Add FOO to the beginning of each line
sed 's/$/FOO/g'                                               Add FOO to the end of each line

column -t                                                     Align columns

sed /^$/d                                                     Compress blank lines
paste -s -d" "                                                Convert a list into a single line

apt-get install xml-twig-tools
xml_grep ‘firstName' file.xml --text_only                     Extract data from XML element

grep -oe '[a-zA-Z0-9._]\+@[a-zA-Z]\+.[a-zA-Z]\+'              Find emails
grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b'                    Find IPs
grep -E '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b'                     Find lines that contain an IP

perl -pe 's/\d{2}\/\d{2}\/\d{2}//g'                           Find dates mm/dd/yy

sed '/[[:blank:]]/d'                                          Find lines that contain a single word
grep 'FOO'                                                    Find FOO
sed '/FOO/I,+12 d'                                            Find FOO, and delete that and the next 12 lines
sed 's/FOO.*$//g'                                             Find FOO, and delete to the end of file
sed 's/FOO/\n&/g'                                             Find FOO, and insert a new line and FOO
grep 'FOO\|BAR'                                               Find FOO, and lines that contain BAR
sed '1N;N;/\(.*\n\)\{2\}.*FOO/P;$d;D'                         Find FOO, and print the second line before that
awk -v n=-2 'NR==n+1 && !NF{next} /FOO/ {n=NR}1'              Find FOO, if the next line is blank, delete it

awk -v n=-2 'NR==n+1 && !NF{next} /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/ {n=NR}1'
                                                              Find lines that start with IP, if the next line is blank, delete it

awk -v n=-2 'NR==n+1 && NF{print hold} /FOO/ {n=NR;hold=$0;next}1'
                                                              Find FOO, if the next line is blank, delete line containing FOO

awk '/FOO/ { FOO = 1; next }  FOO == 1 && /^$/ { FOO = 0; next }  { FOO = 0 }  { print }'
                                                              Find FOO, if the next line is blank, delete both lines

awk -v n=-2 'NR==n+1 {if($0 ~ /BAR/) { next; } else { print hold } } /FOO/ {n=NR;hold=$0;next}1'
                                                              Find FOO, if the next line contains BAR, delete both lines

sed 's/.* //'                                                 Find lines that contin a space and print from the space to the end of the line
grep -E 'FOO|BAR'                                             Find lines that contain FOO or BAR
grep '[0-9]'                                                  Find lines that contain a number
grep '[0-9]$'                                                 Find lines that end with a number
grep 'FOO$'                                                   Find lines that end with FOO
sed 's/FOO$//'                                                Find lines that end with FOO, and delete FOO

grep '^[0-9]'                                                 Find lines that start with a number
grep '^FOO'                                                   Find lines that start with FOO
sed '/^FOO/{n;d;}'                                            Find lines that start with FOO, and delete the following line
printf '%s\n' 'g/^FOO/-1d' w | ed -s                          Find lines that start with FOO, and delete the previous line
sed '/^FOO/i\ '                                               Find lines that start with FOO, and insert a line before
sed '/^FOO/a\ '                                               Find lines that start with FOO, and insert a line after
sed -e :a -e '$!N;s/\nFOO/ /;ta' -e 'P;D'                     Find lines that start with FOO, insert a space and append to the previous line

fmt -w 25                                                     Limit the number of characters on a line to 25

sed -n '/FOO/,$p'                                             Print from FOO to the end of the file
sed s/FOO.*//                                                 Print from FOO to the end of the line
sed -n '5,/^$/p'                                              Print from the 5th line to the first blank line
awk 'NR == 1 || NR % 3 == 0'                                  Print the first and every third line
awk 'NR % 3 == 0'                                             Print every third line
sed -n '/FOO/,/BAR/p'                                         Print lines between FOO and BAR
sed -e '/./{H;$!d;}' -e 'x;/FOO/!d;'                          Print paragraphs that contains FOO
awk '{print $2 " " $1}'                                       Print the second column, insert a space, then the first column

find . -type f -empty -exec rm "{}" \;                        Remove all empty files
sed 's/[A-Z]\{2\},//g'                                        Remove any 2 capital letters followed by a comma
sed '/^$/d'                                                   Remove blank lines
sed 's/[0-9]\{2\}\/[0-9]\{2\}\/[0-9]\{2\}//g'                 Remove dates (mm/dd/yy)
cat -s                                                        Remove double spacing
sed 's/^....//'                                               Remove first 4 characters from each line
sed '1,5d'                                                    Remove first 5 lines
sed 's/^[ \t]*//; s/[ \t]*$//'                                Remove leading and trailing whitespace from each line
sed 's/^[ \t]*//'                                             Remove leading whitespace from each line
sed '/FOO/,/BAR/d'                                            Remove lines between FOO and BAR
awk '/FOO/{f=1} (!f || f>2){print} (f && /BAR/){f++}'         Remove lines from FOO and the second BAR
awk '$2 !~ /[a-z]/'                                           Remove lines that contain [a-z] in the second column
sed '/[[:blank:]]/!d'                                         Remove lines that contain a single word
awk 'NF != 2'                                                 Remove lines that contain two words
awk '!(/FOO/ && /BAR/)'                                       Remove lines that contain FOO and BAR
printf '%s\n' 'g/FOO/d\' '-d' w | ed -s                       Remove lines that contain FOO and the previous line
sed '/@.*@/d'                                                 Remove lines that contain two @ symbols
sed '/[0-9]/d'                                                Remove lines that contain a number
sed '/[0-9]$/d'                                               Remove lines that end with a number
sed '/FOO$/d'                                                 Remove lines that end with FOO
sed '/^[0-9]/d'                                               Remove lines that start with a number
sed '/^FOO/d'                                                 Remove lines that start with FOO
grep -Ev '^\b([0-9]{1,3}\.){3}[0-9]{1,3}\b'                   Remove lines that start with an IP
sed '/^.,/d'                                                  Remove lines where the second letter is a comma
cat tmp | tr -d "\n" | tr -d " "                              Remove new lines and spaces. Ex copying a hash from Rubeus for use in Mimikatz
cat tmp | rev | sed 's/^[ \t]*//' | cut -d ' ' -f2- | rev     Remove the last column
head -n -5                                                    Remove the last 5 lines
sed 's/[ \t]*$//'                                             Remove trailing whitespace from each line

sed 's/ \{2,\}/,/g'                                           Replace 2 or more spaces with a comma
sed 's/\.\.\.//g'                                             Replace 3 periods with nothing
sed 's/\t/:/g'                                                Replace a tab with a colon. Convert IP and ports columns from Excel into IP:port
sed 's/FOO/BAR/g'                                             Replace FOO with BAR
find . -type f -exec sed -i 's/FOO/BAR/g' {} +                Replace FOO with BAR recursively in the current directory
sed '/TEST/!s/FOO/BAR/g'                                      Replace FOO with BAR, except on lines that contain TEST
sed '/TEST/s/FOO/BAR/g'                                       Replace FOO with BAR, on lines that contain TEST
sed 's/FOO//g'                                                Replace FOO with nothing
sed -n 'H; ${x; s/\n/|/g; p}'                                 Replace 'new line' with a pipe '|'
cat tmp | tr ';' '\n'                                         Replace semicolon with a new line
sed 's/\([^,]*,\)\{7\}[^,]*,/&\n/g'                           Replace the 8th comma with a new line

sort -k2                                                      Sort by the second column
sort -n -u -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4                   Sort IPs

sed 's/[^ ]\+/\L\u&/g'                                        Title case

tr -d '\t'                                                    Delete a tab
tr ',' '\n'                                                   Translate a comma to a new line
tr -s ' '                                                     Translate any number of spaces to a single space
tr '[a-z]' '[A-Z]'                                            Translate lower case to upper case
tr '[A-Z]' '[a-z]'                                            Translate upper case to lower case

sed "s/$FOO./$FOO/g"                                          Variables - use double quotes with sed or grep
------------------------------------------------------------------------------------------------------------------------------------------------------

# Check for argument. If not given, print the usage
if [ -z "$1" ]; then
     echo "Usage: $0 <domain name>"
     exit
fi

# Chech for argument. Give feedback to user
echo -e "Usage: ./test.sh <target IP> <scan type>"
if [ "$2" == "All" ]; then
     echo "Running all scans on $1."
else
     echo "Running a $2 scan on $1."
fi

# Check for root
if [[ $EUID -ne 0 ]]; then
     echo
     echo "[!] This script must be ran as root."
     exit
fi

# Check for no answer
if [ -z $location ]; then
     f_Error
fi

# Check for wrong answer
if [ ! -f $location ]; then
     f_Error
fi

# Check for two variables
echo -n "Enter color: "
read color
echo -n "Enter another color: "
read color2

if [ $color = "red" ] && [ $color2 = "grey" ]; then
     echo
     echo "The Wall won't fall."
     echo
     exit
else
     echo
     echo "Those colors are crap."
     echo
fi

# Validate input is a number and that it is greather than 0
if ! [[ "$number" =~ ^[0-9]+$ ]] || [[ "$number" -le "0" ]]; then
     f_error
fi

# Check for valid port number
if [[ $port -lt 1 || $port -gt 65535 ]]; then
     echo "Invalid port."
     exit
fi
------------------------------------------------------------------------------------------------------------------------------------------------------

# Colors

RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
BLUE='\033[1;34m'
NC='\033[0m'

echo -e "I ${RED}love${NC} Discover."
------------------------------------------------------------------------------------------------------------------------------------------------------

# Compare two dates

date1=$(date +"%s")
date2=$(date +"%s")
diff=$(($date2-$date1))
echo "$(($diff / 60)) min and $(($diff % 60)) sec."
------------------------------------------------------------------------------------------------------------------------------------------------------

# Files and folders

if [ -e test ]; then
     echo "This file exists."
fi

if [ ! -e test ]; then
     echo "This file does not exist."
fi

if [ ! -s test ]; then 
     echo "This file is empty."
fi

if [ -d test ]; then
     echo "This folder exists."
fi

if [ ! -d test ]; then
     echo "The folder does not exist."
fi
------------------------------------------------------------------------------------------------------------------------------------------------------

# If a process is running, kill it

pid=$(ps -ef | grep 'discover.sh' | grep -v 'grep' | awk '{print $2}')

if [ -n "$pid" ]; then
     kill -9 $pid
fi
------------------------------------------------------------------------------------------------------------------------------------------------------

# Read in a file and do something

for i in $(cat subdomains); do
     host $i | grep 'has address' | cut -d ' ' -f4
done

while read i; do
     host $i | grep 'has address' | cut -d ' ' -f4
done < subdomains
------------------------------------------------------------------------------------------------------------------------------------------------------

# Special characters to escape

~|`|!|@|#|\$|%|\^|&|\*|\(|\)|_|-|\+|=|{|\[|}|]|\|:|;|"|<|,|>|\.|\?|/|
------------------------------------------------------------------------------------------------------------------------------------------------------

# Use a variable and set a constant

if [ "$payload" == "1" ]; then
     format="raw"
     platform="android"
else
     format="exe"
     platform="windows"
fi
------------------------------------------------------------------------------------------------------------------------------------------------------

# xterm

Open an xterm window in the center of the screen, run a command, and stay open
xterm -hold -bg blue -fg white -geometry 90x10 -T "Test ping" -e ping -c3 google.com

Open an xterm window in the top right corner of the screen, run a command, and stay open
xterm -hold -bg blue -fg white -geometry 90x10-0+0 -T "Test ping" -e ping -c3 google.com

{'fraction_non_alphanumeric': 0.18477262990391088, 'fraction_numerical': 0.014811187955199217, 'mean_word_length': 0.8366211431461811, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 374, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '176711', 'n_tokens_mistral': 7682, 'n_tokens_neox': 7276, 'n_words': 3243}