answersLogoWhite

0


Best Answer

You don't need a script, just use the 'wc' command:

# Lines

wc -l <file>

# Words

wc -w <file>

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a shell script that counts the no of lines and words in a file?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a shell script which counts the last 10 lines present in a given file?

You don't need a shell script to do this - just use the 'tail' command.


How do you write a shell script which counts the number of lines and words present in a given file?

#!/bin/sh wc -lw "$1"


Write a shell script that counts a number of unique word contained in the alphabetical order line by line?

use python, shell is stupid


Write a shell script to show that user is logged in or not?

You don't need a shell script for that; use either 'whoami' or 'id'


Shell script that counts the no of lines and words in a file without using wc command?

A shell script by itself would be a fairly poor way of doing this; using something like awk or perl with a pattern match for a word would be a much better choice. There are many examples on the net for this type of process using perl, for example.


When might it be necessary or advisable to write a shell script instead of a shell function?

A shell function will do nothing unless it is explicitly called by other code, typically in a shell script. A shell script is a runnable, executable process, which can call other shell scripts and/or functions. The question might be worded backwards - it is necessary to write shell functions for shell scripts when certain logical functionality is required to be performed multiple times. Consider a shell function equivalent to a program subroutine - they operate the same way.


How do you add two matrices using Linux shell script?

write ashell script to add awo matrix using array.


How do you write a shell script to enlist the processes being run?

#!/bin/sh PS -a


How do you write a statement in DOS using shell script to display a word?

We can not perform Shell Scripting in DOS, we can do Batch programing in DOS..


What is the command to execute a shell script?

If the shell script is readable and executable then to execute it just type the name of the shell script file. Otherwise, you can explicity call a shell interpreter to run the file as a shell script, i.e., ksh myfile


How do you write a script which lists the 10 Shell System variables?

You don't need a shell script to do that. Since you don't say what 10 shell variables you want, you can list them all by using the 'set' command to list all known in-use shell variables in the current session.


Write a shell script to count the number of times is appears in a given text file?

You don't need a shell script to do this; use the 'grep' command with the '-c' option to count the number of occurrences of some pattern.