This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This method finds last name separated by /, helps in getting directory or file name without path. | |
print_name() { | |
echo $1 | awk -F "/" '{ print $NF }' | |
} | |
dir_name=/Users/tanzyy/_temp/logshomedir/* | |
for d in $dir_name; do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script shows how to make multiline comment. Indentation is mandatory inside "comment". | |
echo "This should get printed: Before multiline comment" | |
: <<'Comment' | |
echo "This should NOT get printed: Inside multiline comment" | |
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#This script shows how to pass shell variable to awk using option -v | |
index_pos="4" | |
search_string="31/Mar/2017:03:58:38" | |
cat ~/Desktop/tempp.txt | awk -v pos=$index_pos -v ss=$search_string '{ if($pos==ss) print $0 }' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script shows how to declare array and and add vlaues to it. | |
result=() | |
result+=('foo') | |
result+=('bar') | |
for i in "${result[@]}" | |
do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# On MAC date -d option does not work rather -v. | |
# Below code logic is as follows: | |
# Create folders with date(in format YYYY-MM-DD) with consecutive dates until it reaches to input difference | |
# Here variable datediff is 28 meaning from current date, it will generate dates until there is difference of 28. | |
now=$(date -v -1d +"%Y-%m-%d") | |
datediff=28 | |
for (( c=0; c<=$datediff; c++ )) |