Skip to content

Instantly share code, notes, and snippets.

View quickgrid's full-sized avatar

Asif Ahmed quickgrid

View GitHub Profile
@quickgrid
quickgrid / RecursiveDirectoryTraversal.sh
Created April 1, 2016 04:15
The code below traverses all the directories recursively inside the passed in command line argument directory. While traversing recursively if it finds a regular file with executable permission it remove the permission for the owner.
#!/bin/bash
#Recursively traverse the directories
traverseDirectory(){
for fileName in `ls $1/`
do
echo "$1/$fileName"
if [ -x $1/$fileName ]; then
@quickgrid
quickgrid / sedInput.txt
Created April 1, 2016 04:22
A sample input file to use sed regex to match and replace certain pattern with given string.
abc
oiewjf
cdeoewjfmpew
oiwegm
ab
bc
abc
@quickgrid
quickgrid / sedStringReplace.sh
Created April 1, 2016 04:25
The code replaces all the matches in the given text file with the given string.
#!/bin/bash
pattern="abc"
replacedValue="cde"
sed -i "s/$pattern/$replacedValue/g" sedInput.txt
@quickgrid
quickgrid / TerminalArgumentFileRead.sh
Created April 1, 2016 04:43
Reads the file line by line that was passed in as the first argument.
#!/bin/bash
#Pass arguments of txt file via command line
while read line
do
echo $line
done < "$1"
@quickgrid
quickgrid / ReadLineInThreeVariables.sh
Last active April 1, 2016 04:51
The shell script reads line into three variables where in each line there are three string separated by space.
#!/bin/bash
while read ip datee timee
do
echo "Details:"
echo $ip
echo $datee
echo $timee
echo ""
done < "$1"
@quickgrid
quickgrid / FunctionArgumentPassing1.sh
Created April 1, 2016 04:55
Example of bash function argument function passing.
#!/bin/bash
readFile(){
while read line
do
echo $line
done < "$1"
}
@quickgrid
quickgrid / FunctionArgumentPassing2.sh
Created April 1, 2016 04:59
Example of argument passing to a function.
#!/bin/bash
#Recursively traverse the directories
traverseDirectory(){
for fileName in `ls $1/`
do
if [ -d $1/$fileName ]; then
echo "$1/$fileName"
@quickgrid
quickgrid / RecursiveDirectoryFilePrintContent.sh
Created April 1, 2016 05:07
Recursively traverse the Directories and Print the file contents inside those directories.
#!/bin/bash
#Recursively traverse the Directories and
#Print the file contents inside those directories.
readFile(){
while read line
do
echo "$line"
done < "$1"
@quickgrid
quickgrid / ExpressionEvaluation.sh
Created April 1, 2016 05:34
This just an example of expression evaluation different way. Also equality and even odd checking in a different way.
#!/bin/bash
# Do not use space before and after equal sign.
a=1
b=3
sum=`expr $a + $b`
sum=$(( $sum + 5 ))
@quickgrid
quickgrid / SwitchCaseExample.sh
Created April 1, 2016 05:42
Bash switch case example.
#!/bin/bash
#swich case code
echo "yes or no?"
read answer
case "$answer" in