Articles in the shell category

Valid Phone Numbers with shell script

Valid phone numbers must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit) Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone...

shell script to read lines from file

How would you print just the 10th line of a file with the shell script? Shell script is as below: #!/bin/bash k=0 while IFS='' read -r line || [[ -n "$line" ]] do ((k++)) if [ $k -eq 10 ] then echo "Text read from file: $line" fi done < "$1" If you...

shell script to evaluate expression

To evaluate expressions involving decimal places (floating points) "bc -l" is very useful. Your task is to evaluate the expression and display the output correct to decimal places. Shell script is as below: #!/bin/bash read expression printf "%.3f\n"...