Search This Blog

Friday, October 6, 2023

TCL Script 10

Question:
Write a proc to get the collaterals from  different dir

#!/usr/bin/tclsh

proc getPtpxInputs {hm_name run_tag} {

        set comman_path "/home/kalam/pnr_inputs/"

        set run_area    "$comman_path/$hm_name/$run_tag"

        set ptpx_inputs [list ${hm_name}.v ${hm_name}.map ${hm_name}.sdc]

        set upf_path    [list ${hm_name}.upf]

        foreach input $ptpx_inputs {

               set file_path [file join $run_area $input]

               set upf_path  [file join $comman_path/power_intent $upf_path]

               if {[file exists $file_path] && [file exists $upf_path]} {

                        puts "$file_path"

             }

       }

       puts "$upf_path"

   }

  set hm_name top

  set run_tag run1

getPtpxInputs $hm_name $run_tag

Usage of the script <proc_name> <hm_name> <run_tag>

output:

kalam@DESKTOP-OSJTLNE:~/pnr_inputs$ tclsh  getptpx_inputs.tcl

/home/kalam/pnr_inputs/top/run1/top.v

/home/kalam/pnr_inputs/top/run1/top.map

/home/kalam/pnr_inputs/top/run1/top.sdc

/home/kalam/pnr_inputs/power_intent/top.upf

Monday, October 2, 2023

Shell script 20

Question: Get the files from different directories by using case  statement

Answer:

#!/usr/bin/bash

if [ $# -eq 0 ]

then

        echo "Usage: $0 <case_number>"

        exit 1

fi

case_number="$1"

case "$case_number" in

        1)

                dir="/home/kalam/pnr_inputs/"

                files=("top.spef" "top.vi") ;;

        2)

                dir="/home/kalam/synth_inputs/"

                files="leaf_inst.rpt" ;;

        *)

                echo "Invalid case_number, Please choose 1 or 2"

                exit 1 ;;

esac

if [ ! -d "$dir" ]

then

        echo "Directory $dir does not exist"

        exit 1

else

        for file in "${files[@]}"

        do

        file_path="${dir}${file}"

        if [ -f "$file_path" ]

        then

                echo "$file_path"

        else

                        echo "File $file_path not found"

        fi

done

fi


Shell script 19

Question: write a script to print your lucky number

Answer:

#!/usr/bin/bash

read -p "What is your lucky number?" num

case  $num in

        1)

                echo "your lucky number is one";;

        2)

                echo "Your lucky number is two";;

        *)

                echo "None"

esac

Output:

kalam@DESKTOP-OSJTLNE:~$ sh  case_statement.sh

What is your lucky number? 1

your lucky number is one

Shell script 18

Question: Usage of  $*,$1,$#,$0,$@,$?

 #!/usr/bin/bash

present_working_dir=`pwd`

echo "script name $present_working_dir/$0"

echo "1st argument $1"

echo "2nd argument $2"

echo "Previous command is success or not if yes it will give 0: $?"

echo "$*"

echo "total number of arguments $#"

echo "Arguments names $@"


Shell script 17

 CUT command usage

Question:

Usage of the cut command 

cut -d "," -f 1 cut_examples.sh

cut -d "," -f 2 cut_examples.sh

cut -d "," -f 3 cut_examples.sh

cut -c 1-4 cut_examples.sh

Sunday, October 1, 2023

Shell script 16

Question: Read the file content by read command

#!/usr/bin/bash 

while read msg

do

    echo "$msg"

done  <  "/home/kalam/filename.sh"

Explanation:

<  flag is used to open the file
read command is used to read the content

Shell script 15

Question: Variable assignment 

#!/usr/bin/bash

variable="Raju"

echo "$variable"

Question: Command substitution 

#!/usr/bin/bash

variable=`date`

echo $variable

FORMAT=$(date +%Y-%m-%d,%H-%M-%S)

echo "date: $FORMAT"




Shell script 14

Question: Backup the important files and directory's with the timestamp

Answer:

#!/usr/bin/bash

#source directory to back

source_dir="/home/kalam/raju"

#backup directory

backup_dir="/home/kalam/Professor"

#creating the timestamp for the backup

timestamp=$(date +"%Y%m%d%H%M%s")

backup_sub_dir="$backup_dir/backup_$timestamp"

mkdir -p "$backup_sub_dir"

rsync -av "$source_dir/" "$backup_sub_dir/"


Output:

kalam@DESKTOP-OSJTLNE:~$ sh back_up_dir_files.sh

sending incremental file list

./

sent 58 bytes  received 19 bytes  154.00 bytes/sec

total size is 0  speedup is 0.00

kalam@DESKTOP-OSJTLNE:~$ ls Professor/

backup_2023100120341696172680  backup_2023100120341696172691  backup_2023100120351696172717  backup_2023100120381696172901

Shell script 13

Question:

Write a script to replace a pattern with other pattern without opening the file.

Answer:

#!/usr/bin/bash

inputfile="/home/kalam/filename.sh"

if [ -e $inputfile ]

then

        echo "File is exists in the following path: $inputfile"

        #pattern to replaced

        pattern_to_replace="state_name"

        #replacement pattern

        replacement_text="STATE_NAME"

        sed -i "s/$pattern_to_replace/$replacement_text/g" "$input file"

        echo "pattern '$pattern_to_replace' replaced with '$replacement_text' in '$inputfile'"

else

        echo "file not found: $inputfile"

        echo "Please provide realpath of the file and re-run the script\n Thank you for using this script"

fi

output:

echo "Please Provide the user name and state name"

read name STATE_NAME

echo "User provided name is :$name and His state name is : $STATE_NAME "

if [ "$STATE_NAME" =  "andra" ]; then

        echo "$name speaks Telugu"

else

        echo "$name does not speak Telugu"

fi





Shell script 12

Question:

Open a file and read the content and print the lines one by one, also check the file is exist or not if it is absent say file is absent  

Answer:

#!/usr/bin/bash

path="/home/kalam/filename.sh"

if [ -e $path ]

then

        echo "File is exists in the following path: $path"

        for line in $(cat "$path")

        do

                echo "line: $line"

        done

else

        echo "file is absent"

        echo "Please provide realpath of the file and re-run the script"

        echo "Thank you for using this script"

        exit 1

fi



Basic Linux commands

How to create a file

    touch filename

    Explanation: touch used to create a file 

How to create multiple files at a time

    touch Math's Physics Chemistry Social

    touch file {1..1000}

    Explanation : We can create multiple files at a time 

    It will create 1000 files at a time in the current directory

Command to display the contents of the file

    cat filename

    cat -n filename

    cat -b filename

    Explanation: It will display from beginning of the line to end of the line forward direction 

    -n flag is will give you the line number 

    -b flag will give you line numbers only for non-blank lines

Command to display form end of the file to beginning of the file 

    tac filename 

    Explanation : It will display from end of the file to beginning of the file 

Redirecting the output of the command to a file

    cat file > output.text

    Explanation: file content is redirected to the output.text

Command to appending the content 

    cat filename >> output.text 

    Explanation: It will to the end of the line

Shell script 11

Question:

How to check the file is exist or not and if it exists then the size is zero or not

file="/home/kalam/if_condition.sh"

if [ -e $file ]

then

echo “File exists”

else

echo “File does not exist”

fi

## Checking for file size is Zero or not

 if [ -s $file ]

then

echo “File size is zero”

else

echo “File size is not zero”

fi



Shell script 10

Question:

How to check whether the file has read, write and execute permissions 

Answer:

 #!/usr/bin/bash

file=“/home/kalam/file.text”

## checking for write permissions 

if [ -r $file ]

then

echo “File has read access”

else

echo “File does not have read access”

fi

## checking for write permissions 

if [ -w $file ]

then

echo “File has write permission”

else

echo “File does not have write permission”

fi

## checking for execute permission 

if [ -x $file ]

then

echo “File has execute permissions”

else

echo “File does not have execute permission”

fi



Shell script 9

Question:

String length is empty or not

Answer:

#!/usr/bin/bash

mystring="I love my country"

if [ -z "${mystring}" ]

then

        echo "mystring length is not zero"

else

        echo "$mystring"

fi

Output:

kalam@DESKTOP-OSJTLNE:~$ sh string_length_zero_or_not.sh

I love my country

Shell script 8

Question:

How to convert from one case to other case

#!/usr/bin/bash

## this script is used for converting from lower case letters to upper case letter

user_name=Raju

user_fname=LAWRENCE

echo "$user_name" | tr '[:lower:]' '[:upper:]'

echo "$user_fname" | tr '[:upper:]' '[:lower:]'


Output:

kalam@DESKTOP-OSJTLNE:~$ sh case_sen.sh

RAJU

lawrence                        

Saturday, September 30, 2023

Shell script 7

Question:

Read the csv file and print the respective filed column by using the input filed separator.

Answer:

#!/usr/bin/bash

path="/home/kalam/names_and_employ_id.csv"

while IFS="," read name id

do

        echo "Employee name is: $name"

        echo "Employee id is: $id"

done < $path

output:

kalam@DESKTOP-OSJTLNE:~$ sh field_reading.sh

Employee name is: Name

Employee id is: id

Employee name is: raju

Employee id is: 1010

Employee name is: Naga

Employee id is: 1011

Employee name is: Naresh

Employee id is: 101


gvim names_and_employ_id.csv

Name,id

raju,1010

Naga,1011

Naresh,101


Note:

IFS Input Filed Separator in the *.csv filenames and employee id's are separated with , 


Shell script 6

Question:

Grep the multiple patterns in one shot and print the lines which matches from the file. Include if the no of arguments are not matching to the total no of arguments

Answer: 

 #!/usr/bin/bash

#command line arguments if the no of arguments are not matching the script will exit

path=$1

pattern1=$2

pattern2=$3

echo "total number of arguments $#"

if [ ! "$#" = 3 ]

then

        echo "Please provide the required argunments, No of arguments are not matching"

        echo "Usage of this script is sh <<filename.sh>> arg1 arg2 arg3"

        echo "Rerun the script with the required arguments\nThank you for using this script"

        exit 1

else

        echo "Controller starts executing the script"

        required_pattern=$(grep -E "$pattern|$pattern2" $path)

        echo "$required_pattern"

fi


Output:

kalam@DESKTOP-OSJTLNE:~$ sh command_lin_arguments.sh filename.sh name Telugu

total number of arguments 3

Controller starts executing the script

echo "Please Provide the user name and state name"

read name state_name

echo "User provided name is :$name and His state name is : $state_name "

if [ "$state_name" =  "andra" ]; then

        echo "$name speaks Telugu"

else

        echo "$name does not speak Telugu"

fi

Note:

https://www.blogger.com/blog/post/edit/7948084828664881049/5347819150177177366?hl=en

consider this script name i used for above example 


Shell script 5

 #!/usr/bin/bash

#command line arguments if the no of arguments are not matching the script will exit

path=$1

pattern=$2

echo "total number of arguments $#"

if [ ! "$#" = 2 ]

then

        echo "Please provide the required arguments, No of arguments are not matching"

        echo "Usage of this script is sh <<filename.sh>> arg1 arg2"

        echo "Rerun the script with the required arguments\n Thank you for using this script"

        exit 1

else

        echo "Controller starts executing the script"

        required_pattern=$(grep $pattern $path)

        echo "$required_pattern"

fi


Output:

kalam@DESKTOP-OSJTLNE:~$ sh  command_lin_arguments.sh

total number of arguments 0

Please provide the required argunments, No of arguments are not matching

Usage of this script is sh <<filename>> arg1 arg2

Rerun the script with the required arguments

Thank you for using this script


! --> Is Used to for negation of condition

$# --> It returns the total number of arguments 

$1 -> Indicates 1st argument

$2 --> Indicates 2nd argument

Shell script 4

Question:
Write a script whether the provided path type is file or dir

 #!/usr/bin/bash

#this script is for command line arguments

path=$1

if [ -f $path ]

then

        echo "the provided path type is file, you can read the content in any editor"

else

        if [ -d $path]

        then

        echo "the provided path type is not a file ,it is a Dir"

        fi

fi


Output :

the provided path type is file, you can read the content in any editor


Note;

-f  checks for file type

-d checks for directory 

Shell script 3

Question2:
Write a script whether the file is readable or not, if it is readable print the file content on the terminal after 5 sec

Answer:

Path="/home/kalam/filename.sh"

echo "User provide path is : $Path"

sleep 5

if [ -e $Path ]

then

        echo "file is present in the $Path"

        if [ -r $Path ]

        then

                echo "the file $Path is readable"

                info=$(cat $Path)

                echo $info

        else

                echo "file is not in readable format"

        fi

else

        echo "File is absent in the given path: $Path"

        echo "Please correct the path and rerun the script"

        echo "thank you for using this script"

fi


Output:

User provide path is : /home/kalam/filename.sh

file is present in the /home/kalam/filename.sh

the file /home/kalam/filename.sh is readable

echo "Please Provide the user name and state name" read name state_name echo "User provided name is :$name and His state name is : $state_name " if [ "$state_name" = "andra" ]; then echo "$name speaks Telugu" else echo "$name does not speak Telugu" fi


Note: 
-r flag is used check for readable the file or not if yes condition will execute

Shell script 2

 Shell scripting 2

Question:

Read the user inputs and check for that whether it is available or not ,If it is available print the user inputs are available else print not available , also your output should print after 10 Sec

Answer:

Path="/home/kalam/filename.sh"

echo "User provide path is : $Path"

sleep 10

if [ -e $Path ]

then

        echo "file is present in the $Path"

else

        echo "File is absent in the given path: $Path"

        echo "Please correct the path and rerun the script"

        echo "thank you for using this script"

fi

Output:

User provide path is : /home/kalam/filename.sh

file is present in the /home/kalam/filename.sh

Note:

-e is the flag which is used to check for the existence of the file or directory

Shell script 1

If condition

Example:

echo "Please provide the user name and state name"

read name state_name

echo "User provided name is :$name and His state name is : $state_name "

if [ "$state_name" =  "Andra" ]; then

        echo "$name speaks Telugu"

else

        echo "$name does not speak Telugu"

fi


Output:

Please Provide the user name and state name

Balakrishna andra

User provided name is :Balakrishna and His state name is : andra

Balakrishna speaks Telugu

Shell scripting

Read the user inputs and execute the script

Example1: 

echo  -n  "Please type your required info"

read info

echo "You're required information is: $info"

Example2:

read -p "Please type your required info" info

echo  "You're required information is: $info""


Example and Example2 both gives the same but, in the example1 there is no read -p

Example2 : read -p --> it will ask a query and assigned to var

Wednesday, September 13, 2023

Lists in TCL scripting

 LISTS keywords and It's Usage 

lindex

lindex is a keyword and it will print the index value of the list.
Example:
   set  NameList  "Naresh Prashanth Sanjeev Manoj  Rajendhar"
   puts [lindex $NameList 0] ; #it will print the 0th index of NameList i,e Naresh
   puts [lindex $NameList 1] 
   puts [lindex $NameList 2] 
         
Explanation:

List index will start from "0" 
Naresh    -----> index 0
Prashanth  ---> index 1
Sanjeev     ---> index 2
Manoj      ----> index 3
Rajendhar ---> index 4

*****************************************************************************

llength

llength is a keyword -it will give you the size of the list.

Example:           
  set  NameList  "Naresh Prashanth  Sanjeev Manoj Rajendhar"
  puts [lindex   $NameList 0] 
  puts [llength  $NameList ] ; #it will print 5 because 5 Names are there in the NameList  

****************************************************************************

lsort

lsort is a keyword -it will sort the list means ascending/Descending order of the List      

Example1:
 set  NumList  "0  9 8 1 3 4"
 puts [lsort $NumList  -ascending ] ; # it will print from small to big
 puts [lsort $NumList  -descending ] ; # it will print from big to small 

 Explanation 1:
 In this example I am taking numerical values     
 Ascending values --> small to big like 0 1 3 4 8 9
 Descending values --> big to small like 9 8 4 3 1 0

Example2:         
 set flist  "Banana Anar Avagado Watermelon Grapes Mango "
 puts [lsort $flist] ; # it will print in alphabetical order

*************************************************************************

lsearch

lsearch is a keyword to search for the element if it is matches it will return 0 otherwise it will return -1 

Example:
    set str "Nag Raju Chandu Mahi"
    lsearch $str Nag

************************************************************************


TCL Basics

 TCL  
Tool Command language

Keywords in TCL

  • puts
  • expr
  • $
  • incr
  • info exists
  • split
  • concat

    LIST keywords

    • lindex
    • llength
    • lsort
    • lreplace
    • linsert
    • lappend
    • lsearch
    • lappend

    Saturday, August 12, 2023

    Basics power anaysis

    Power

    • Dynamic power:
      • Power consumed by the cell when it is active mode.
    • Switching Power:
      • Power dissipated by the charging and discharging of the output load capacitance of a cell is called switching power.
      • Switching power of a cell is a function of output load capacitance and the rate of logic transitions.
    • Internal Power:
      • Power dissipated by charging and discharging of internal capacitance within the boundary of the cell is called Internal power.
    • Short circuit power
      • Power dissipated when a small amount of time both the PMOS and NMOS transistors are turns on.
      • there is short circuit established from VDD to VSS.
    • Leakage power
      • Power dissipated by the cell or circuit when it is in stand by mod or inactive mode.
        

    What is the sanity checks you have done for STA?

     Sanity checks for STA: Linking Checks: We need to check., is there any missing modules or missing pins in a library. this is done by link c...