Unix and Shell Scripting all Cognizant Handson Solutions
In this post we covered all the Unix & Shell Scripting Cognizant Handson solutions tekstac.
Introduction to Unix
List-of-Files-2
ls -r
List-of-Files-3
ls -m
File System
Copy File 5
cp livingthings/birds/flyingbirds/eider livingthings/animals/mammals/
Copy File 6
cp cp livingthings/birds/flyingbirds/eagle livingthings/birds/nonflyingbirds/
Copy Directory
cp -r livingthings/birds livingthings/plants/
Copy Complete Directory
cp -r mydir/colors/basic mydir/colors/blended mydir/shape/
Move File 1
mv mydir/animals/mammals/dog mydir/shape
Move File 2
mv mydir/animals/reptiles/snakes mydir/shape
Filters
Find String 7
grep "^echo" teknoscript.txt
Find String 8
grep "[^#]" teknoscript.txt # grep -v "^#" teknoscript.txt
Grep Command – 1
grep ";$" employee.txt
Grep Command – 2
grep -v ";$" employee.txt
Bourne Shell
Script – Pattern Printing
rows=5 for((i=1; i<=rows; i++)) do for((j=1; j<=i; j++)) do echo -n "$i" done echo done
ShellScripting
while read line do if [[ $line =~ Male$ ]] then printf '%s\n' $line >> male_nominee.txt fi if [[ $line =~ Female$ ]] then printf '%s\n' $line >> female_nominee.txt fi done < names.txt
Script Counting
file="$1" w=`cat $file | wc -w` c=`cat $file | wc -c` l=`grep -c "." $file` echo "Number of characters in $file is $c" echo "Number of words in $file is $w" echo "Number of lines in $file is $l"