Question

Write a shell program to count number of characters, number of lines and no. of other symbols in a given file.

24 Apr 2024
Answer :
Word Count : 291

To create a shell script to count the number of characters, lines, and other symbols in a given file, you can use a combination of shell commands such as `wc`, `grep`, and `tr`. Here's a basic script to achieve this:

```bash
#!/bin/bash

# Check if a file is provided as an argument
if [ $# -eq 0 ]; then
    echo "Usage: $0 <filename>"
    exit 1
________ ____ _______ ___ ________ __________ _____ ___ ___ __________ __________ ____.
__________ _____ _________ ___ _____ __________ _______ ___ ______ __________.
______ ____ ______ ___ __________ __________ _________ _____ _________.
__________ ______ _________ ____ __________ ___.
__________ _______ __________ _______ ___ __________.
____ ___ _____ ______ __________ _________ _________ _________ ___ ______ ________ __________.
__________ ________ _______ _____ ______.
_____ ________ _______ ______ ___ _________ __________ __________.
_________ ______ __________ ____ ___ _________ _____ ______ _________ _________.
____ _______ _____ ___ ___ _________.
__________ __________ _____ ______ ____ __________ _______ _____ ________ ___ _______ _______.
____ ___ _________ __________ _______.
____ _____ _____ _____ _______ ___ ______.
______ ______ ______ ___ ___ ____ _____ ______ ____.
________ _______ ______ ___ ____.
___ ___ ________ ________ __________ _____ ______ _______ ___.
_________ _____ _______ ____ ______ __________.
___ ____ _______ ____ _____ ____ _____ ____ ________ _______.
____ ___ ____ ______ _________.
_______ _______ ____ ________ ___ ____ ________ ____ _____ ___ ____.
________ _____ ______ __________ ________ _____ ____ _______.
______ ____ _______ _________ ________ __________ _______.
_______ _______ _________ __________ _____ _______ ______ _________ _________ ___ _____ _______.
_____ _______ _______ ______ ________ ________.
____ ______ ________ _____ ____.
____ _____ _______ __________ __________ _______ ____.
__________ _______ ________ _________ _______ ______ _________ ___ _______ _______.

IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
'; fetch( "query.php?type=1&method=0&lr=0&app=401&mycartproduct=1", { method: "GET", cache: "no-store" } ) .then(function(response) { if (!response.ok) { throw new Error( "HTTP " + response.status ); } return response.text(); }) .then(function(html) { loader.innerHTML = html; /* Your existing function, if available. */ if (typeof updateTotals === "function") { updateTotals(); } else { calculateCartTotal(); } }) .catch(function(error) { console.error( "Cart loading error:", error ); loader.innerHTML = '
Unable to load cart.
'; });}/* ========================================================= CALCULATE TOTAL========================================================= */function calculateCartTotal() { let subtotal = 0; /* Looks for .item-price inside AJAX products. Examples accepted: ₹200 ₹200.00 Rs 200 Rs. 200 200 200.00 */ const prices = document.querySelectorAll( '#loadmycart .item-price' ); prices.forEach(function(element) { let text = element.textContent || ''; text = text .replace(/₹/g, '') .replace(/Rs\.?/gi, '') .replace(/,/g, '') .trim(); let value = parseFloat(text); if (!isNaN(value)) { subtotal += value; } }); updateCartDisplay(subtotal);}/* ========================================================= UPDATE TOTAL DISPLAY========================================================= */function updateCartDisplay(total) { const subtotalElement = document.getElementById('subtotal'); const totalElement = document.getElementById('total'); const checkoutButton = document.getElementById('checkoutButton'); const noItems = document.getElementById('noitems'); const amount = Number(total) || 0; if (subtotalElement) { subtotalElement.textContent = '₹' + amount.toFixed(2); } if (totalElement) { totalElement.textContent = '₹' + amount.toFixed(2); } /* EMPTY CART */ if (amount
Top