Skip to content

Instantly share code, notes, and snippets.

View quickgrid's full-sized avatar

Asif Ahmed quickgrid

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / FileCheckPermissionRemove.sh
Created April 1, 2016 04:03
The code below checks if the given command line argument is a regular file. If it is then it checks if the file is executable. Finally if the file is executable the code removes the execution permission for the owner.
#!/bin/bash
removeExecutablePermission(){
if [ -f $1 ]; then
#echo "regular file"
if [ -x $1 ]; then
#echo "remove permission"
@quickgrid
quickgrid / log.txt
Created April 1, 2016 03:52
Just a bunch of ip address, time and city data to perform time interval regular expression.
192.1.4.09 10:30 Arsenal
110.13.5.67 5:12 Chelsea
192.1.45.67 23:21 Man United
199.13.8.23 8:33 Man city
172.11.22.2 18:45 Arsenal
133.13.8.23 10:00 Moon colony
112.11.22.2 8:00 Mars colony
103.13.8.23 9:00 Jupiter colony
12.11.22.2 8:59 Europa colony