Posts

7 Linux Tips for Displaying Contents of File in Linux

Image
  Tamizh Tech Tutorial 7 Linux Tips for Showing File Contents in Unix / Linux Linux Tips Here you can find several tips for displaying file contents in unix / linux terminal with examples. They are Using cat command Using head command Using tail command Using more command Using less command Using nl command Using nano command (pico command) 1. Using cat Command This command will take a file as an input and display it on the standard output which is the terminal output. Syntax         cat filename Example 2. Using head Command This command will take a file as an input and display the top ten lines by default on the terminal. Syntax         head filename Example 3. Using tail Command This command will take a file as an input and display the bottom ten lines by default on the terminal. Syntax         tail filename Example 4. Using more Command This command will take ...

Cut Command in Linux

Image
 Cut Command in Linux Cut Command This linux command is used to display or cut the specific column(s) or range of columns from the input text file. Syntax cut -c<number> filename Example cut -c5 g1.txt Here, 5th column will be cut and displayed in the terminal. Options -c1,5 -> cut only column1 and 5. -c1 - 5 -> cut columns from 1 to 5. Example 1 - Cut Specific Column (Cut 3rd Column from file f1) Example 2 - Cut Specific Columns (Cut 3rd and 6th Column from file f1) Example 3 - Cut range of Columns (Cut 3rd and 6th Column from file f1) Video Demo

If…elif…else Statement in Shell Script

Image
  If…elif…else Statement This is one of the type of selection statement.   Note It is an important to note that, the simple if, if else and if-elif-else statements should be closed by fi keyword. Syntax if [ condition ] then      true statement elif [ condition ] then      true statement else      false statement fi Example 1 - Shell Style Code Biggest of Three Numbers Source Code echo "Enter the inputs: " read a b c if [ $a -gt $b -a $a -gt $c ]          # -a indicates logical AND then     echo "$a is big" elif [ $b -gt $c ] then     echo "$b is big" else     echo "$c is big" fi Output NOTE It is not possible to directly use logical operator symbols in shell script. The statement below the shows the example Logical Operators     Operator                 ...

While Loop in Shell Script Examples

Image
WHILE LOOP IN SHELL SCRIPT While Loop It is an example of looping statements or iteration statements It is used to execute the statements , if the condition is true otherwise it will skip the loop It is an alternative for normal for loop. Syntax      while [ condition ]       do true statement      done Types of Styles Shell Style C Style Shell Style  Here, we have to use the default shell style of syntax for writing the expression in the shell script. C Style in Shell Script Here, we can write code for expression using c language style using double braces ((expression)) 1. C STYLE BASED FACTORIAL CODE Source Code       echo "--------------------------"      echo -e "\t Factorial Program"      echo "--------------------------"      echo "Enter a Number: "      read n # define the variable      f=1      i=1 # define the while l...

Shell Script If Statement

Image
  Shell Script If Statement If Statement In shell script, if statement is used to execute a single condition or rule If the condition is true , then true statements will be executed otherwise false statements will be executed. Syntax          if [ condition ]         then                true statements         else                false statements         fi Note The keyword fi should be used to complete the if syntax. Example (p1.sh) Source Code      echo "--------------------------------"      echo -e "\t If Statement Example"      echo "--------------------------------"      echo "Enter a number: "      read n # get a remainder of base 2 using c style code      r=$((n%2)) # find the odd or even number using remainder option ...

Rig Linux Command

Image
  Rig Command in Linux Rig Command Rig stands for R andom I dentity G enerator This utility command is used to display the random address and identity This shows the following Random Address (Male or Female Address) Random male address   (using option -m ) Random female address (using option -f ) Random Number of Bulk Addresses using option -c [number] Syntax     rig Example (Displaying Random Addresses) Video Demo

Shell Script Input Arguments in Linux

Image
Shell Script Input Arguments In this blog, the input arguments of shell script will be discussed. Shell script supports three types of input statements. They are Static Inputs  Command Arguments (Positional Arguments) Dynamic Arguments (Runtime Arguments)  1. Static Inputs (Static Arguments) Process of assigning the values to the variables is called as static inputs This is done by using the equal operator named = Syntax     variable-name=initial-value Example     i=99 Script Example (is1.sh) Source Code echo "-----------------------" echo -e "\t Static Inputs" echo "-----------------------" name="Sachin" id=91 echo -e "Name\t: $name" echo -e "Id\t\t: $id" Note Here option -e allows the escape characters such as /t, /n, etc,... Output 2. Command Arguments (Positional Arguments) Process of assigning the values to the script at the time of execution is called as command inputs This is done by using the special parameters like ...