Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

sample bash script

#!/bin/bash
# Editor Amir Ammar 

function SOS {
	echo "Enter: number / files / names / stats <chapter-name> / search <word>/ quit"
}

#########################################A
FILE=$PWD'/'$1 						    #M
if test -f "$FILE" ; then 				#I
	FILE=''		  						#R
else									#A
	echo "File $1 not found"            #M
	exit                                #M
fi                                      #A
for x in  $(cat $(echo $PWD'/'$1)) ; do #R
	FILE=$PWD'/'$x                      #COPY    The Earth With Out Art is Hust 'EH'
	if test -f "$FILE"; then            #RIGHT
    	continue						#E
    else				                #D
    	echo File $x not found			#I
    	exit                            #T
fi                                      #O
done                                    #R
##########################################
while SOS && read -s input ; do
	sweet=$(echo $input | egrep "(number)|(files)|(names)|(stats)[s]*(chapter-[0-9]*[0-9]*)*|(search)[s]*[A-Za-z]*|(quit)")
# Options
case $sweet in 
	"number") ## Find the number of chapters in a given directory  ###############################
	 echo $(cat $(echo $PWD'/'$1) | wc -l)  "chapters"  
	;;
	"files") ## find the name of the files #######################################################
	wd=$PWD
	for chapter in $(cat $(echo $PWD'/'$1)) ; do 
		 echo $( cat $wd/$chapter | head -n1 ): $chapter >> temp1.txt
	done
	sort -V temp1.txt > temp2.txt
	cat temp2.txt
	rm temp2.txt
	rm temp1.txt
	;;
	"names") ## find the title of each chapter ###################################################

	wd=$PWD
	for chapter in $(cat $(echo $PWD'/'$1)) ; do 
		 h="$( cat $wd/$chapter | head -n1 ): "
		 name="$( cat $wd/$chapter | head -n3 | tail -n1)"
		 full="$h$name"
		 echo $full >> temp1.txt
	done
	sort -V temp1.txt > temp2.txt
	sed 's/$/ /g' temp2.txt
	rm temp2.txt
	rm temp1.txt
	;;

	stats*) ## find the number of the worlds and the lines within a chapter #######################
	wd=$PWD
	for chapter in $(cat $(echo $PWD'/'$1)) ; do 
		 ch="$( cat $wd/$chapter | head -n1 ): "
		 line_words="$( cat $wd/$chapter |  tail -n +3 |wc -l) lines, $( cat $wd/$chapter| tail -n +3 | wc -w) words" 
		 full=$ch$line_words
		 echo "$full" >> temp1.txt
	done
	sort -V temp1.txt > temp2.txt
	if [[ $sweet = "stats" ]] ; then
		cat temp2.txt
	else
		if [[ $sweet =~ (stats)[s]*(chapter-[0-9]*[0-9]*)* ]] ; then 
			chap=($sweet)
			grep -i "${chap[1]}" temp2.txt
		fi
	fi
 	rm temp2.txt
	rm temp1.txt
	;;
	
	search*) ## search for a specific word within a chapter and print that amount #################
		arr=($sweet)
		wd=$PWD 
		touch unsorted.txt
		touch sorted.txt
		for chapter in $(cat $(echo $PWD'/'$1)); do 
			h="$(head -n1 $wd/$chapter )"
	 		get=$(cat $wd/$chapter | egrep -w -i ${arr[1]} | wc -l)
	 		full="$h: $get"
	 		if [[ $get -gt 0 ]] ; then
				echo $full >> unsorted.txt
	 		fi
		done
		if [[ $(cat unsorted.txt | wc -l) -gt 0 ]] ; then 
			sort -V unsorted.txt > sorted.txt
			cat sorted.txt
		fi
		rm unsorted.txt
		rm sorted.txt
		;;
	"quit") ## exit ################################################################################
	exit
	;;
esac 
done 
Comment

example bash script

ipconfig /all
ping google.com
tracert google.com
PAUSE
Comment

PREVIOUS NEXT
Code Example
Shell :: powershell select unique 
Shell :: oh my zsh ubuntu 20.04 
Shell :: ubuntu folder size 
Shell :: get path composer 
Shell :: find files size greater than 100mb in linux 
Shell :: ubuntu open all port 
Shell :: git track remote branch 
Shell :: fedora microsoft font 
Shell :: interesting bash scripts 
Shell :: kill x server 
Shell :: osx stop httpd 
Shell :: git commit messages 
Shell :: bash count elements in string 
Shell :: taskkill linux 
Shell :: pip install algolia 
Shell :: ubuntu not showing video thumbnails 
Shell :: ufw add rule with comment 
Shell :: conda install pandas 
Shell :: push local branch upstream 
Shell :: extend recording time in ubuntu 
Shell :: git pull onbly submodule 
Shell :: install faiss in colab 
Shell :: how to remove git commit history 
Shell :: enter user root linux 
Shell :: lumen with specific version 
Shell :: linux command to clean up log files 
Shell :: find command in linux 
Shell :: git add ssh 
Shell :: how to open teminal pycharm 
Shell :: kubectl get namespaces 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =