To list file names consist of only 4 digits.
To list file names consist of only 4 digits. SOLUTION….
Display all blank lines between line 20 and 30 of file test.txt.
Display all blank lines between line 20 and 30 of file test.txt. SOLUTION….
Write a command to replace „RAM‟ with „ROM‟ on line no 10 to 20.
Write a command to replace „RAM‟ with „ROM‟ on line no 10 to 20. SOLUTION….
Write a shell script which takes input of file name and prints first 10 lines of that file. file name is to be passed as command line argument. If argument is not passed then any „C‟ program from the current directory is to be selected.
Write a shell script which takes input of file name and prints first 10 lines of that file. file name is to be passed as command line argument. If argument is not passed then any „C‟ program from the current directory is to be selected. SOLUTION…. #!/bin/bash # Script to print first 10 lines of […]
Write a shell script to prompts the user to enter the time (in 24-hour format) then wish them “Good morning”, “Good afternoon”, “Good evening”, or “Good night” based on the input. (example: If Input is 13 then print Good afternoon)
Write a shell script to prompts the user to enter the time (in 24-hour format) then wish them “Good morning”, “Good afternoon”, “Good evening”, or “Good night” based on the input. (example: If Input is 13 then print Good afternoon) SOLUTION…. #!/bin/bash # Script to greet user based on time input echo “Enter the time […]
Write a script to Check whether file is empty or not, And if file name doesn‟t exist than print appropriate message.
Write a script to Check whether file is empty or not, And if file name doesn‟t exist than print appropriate message. SOLUTION…. #!/bin/bash # Script to check whether file is empty or not echo “Enter file name:” read fname if [ -e “$fname” ]; then if [ -s “$fname” ]; then echo “✅ File ‘$fname’ […]
Write a script to accept a number from user until he enters 0 & find sum of all that numbers.
Write a script to accept a number from user until he enters 0 & find sum of all that numbers. SOLUTION…. #!/bin/bash # Script to find sum of numbers until user enters 0 sum=0 echo “Enter numbers (enter 0 to stop):” while true do read num if [ $num -eq 0 ]; then break fi […]
Write a script to delete all vowels from particular string
Write a script to delete all vowels from particular string SOLUTION…. #!/bin/bash # Script to delete all vowels from a given string echo “Enter a string:” read str # Remove vowels using sed (both lowercase and uppercase) result=$(echo “$str” | sed ‘s/[aeiouAEIOU]//g’) echo “String without vowels: $result” OUTPUT
Accept a string from terminal and echo suitable message if it does not have at least 10 characters
Accept a string from terminal and echo suitable message if it does not have at least 10 characters SOLUTION…. #!/bin/bash # Script to check if entered string has at least 10 characters echo “Enter a string:” read str length=${#str} # count length of string if [ $length -lt 10 ]; then echo “❌ The string […]
Write a script which enters username s& password & check that if the username = sugc& password=98765 then display the valid user message. Otherwise invalid user.
Write a script which enters username s& password & check that if the username = sugc& password=98765 then display the valid user message. Otherwise invalid user. SOLUTION…. #!/bin/bash # Script to check username & password with max 3 attempts correct_user=”sugc” correct_pass=”98765″ attempt=1 max_attempts=3 while [ $attempt -le $max_attempts ] do echo “Attempt $attempt of $max_attempts” […]
