Question

Write a shell script to display the line count over several files(given as arguments)

27 Apr 2023
Answer :
Word Count : 289

 Here is a shell script that displays the line count over several files given as arguments:


#!/bin/bash

# Check if arguments are provided
if [ $# -eq 0 ]
then
    echo "Error: No arguments provided. Usage: $0 file1 file2 file3 ..."
    exit 1
fi

# Loop through each file and display the line count
for file in "$@"
do
    if [ -f $file ]
    then
        echo "$file: $(wc -l < $file) lines"
    else
     

_________ _________ _________ __________ ________ ________ _______ ________ __________ ____.
___ ___ ______ _________ ___.
_____ _____ __________ ______ ____ ______ ______.
__________ _______ ____ __________ _________ _______ ___ _____ _________ _____ ____ ___.
______ ____ ____ _________ _____ _________ _________ __________ ______ __________ ______.
_____ _______ ______ __________ ____ ___ _____ __________ _________ _________ _______.
________ _____ _______ ________ __________ _________ _______ ______ _________ _________.
____ _________ ___ _______ _______ ______ ____ ____ ____ __________ _____.
____ _________ _____ _____ __________ _____ ________ ______.
_____ _____ _________ _______ __________.
_______ __________ ____ ________ ________ __________ _______ _____ ____ _______ _________.
______ _______ ______ _________ _______ _________ ____ ____ ________ __________ ___.
_______ ____ _____ ____ ____ _____ ______ _________ _____.
________ ________ ______ ___ __________ _________.
___ ___ _______ ___ _____ __________.
________ _________ ____ ______ _______ _________ ____ _______ _________ __________ ________ ______.
________ __________ ________ ______ ___ _________ ________ ________.
_____ ______ __________ _____ __________ _______ ____ ________ ________.
_________ ________ _______ ______ _________ ______ _______.
___ ______ _______ ____ ______ ____ _______ _________ __________ ______ __________.
______ __________ _________ ___ _______.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MCSL 204 2022 2023 - Write a shell script to display the line count over several files(give | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→