$ somecommand | wc -l
$ wc -l < /dir/file.txt
3272485
echo Enter the filename
read file
w=`cat $file | wc -w`
c=`cat $file | wc -c`
l=`grep -c "." $file`
echo Number of characters in $file is $c
echo Number of words in $file is $w
echo Number of lines in $file is $l
find . -name '*.php' | xargs wc -l
wc -l
# Let's use a text file called file.txt
# the file contains 5 lines of some programming languages in use today:
$ cat file.txt
#Output:
# JavaScript
# Java
# C
# Python
# C#
# Method 1 'wc'
# 'wc' command can be used to find the number of lines, characters,
# words, and bytes of a file.
$ wc -l file.txt
# Or
$ wc -l < file.txt
# Or
$ wc -l file.txt
# Output:
# 10 file.txt
# OR
# Method 2 - 'sed'
# 'sed' is a stream editor that can be used to perform basic text transformation
# of an input file.
# This command is mostly used for find-and-replace functionality and
# can also be used to find the number of lines of a specified file.
$ sed -n '=' file.txt
# Output:
# 1
# 2
# 3
# 4
# 5
# Or
# sed -n '$=' which gives the overall number of lines
$ sed -n '$=' file.txt
# Output:
# 5
$ somecommand | wc -l
$ wc -l < /dir/file.txt
3272485
echo Enter the filename
read file
w=`cat $file | wc -w`
c=`cat $file | wc -c`
l=`grep -c "." $file`
echo Number of characters in $file is $c
echo Number of words in $file is $w
echo Number of lines in $file is $l
find . -name '*.php' | xargs wc -l
wc -l
# Let's use a text file called file.txt
# the file contains 5 lines of some programming languages in use today:
$ cat file.txt
#Output:
# JavaScript
# Java
# C
# Python
# C#
# Method 1 'wc'
# 'wc' command can be used to find the number of lines, characters,
# words, and bytes of a file.
$ wc -l file.txt
# Or
$ wc -l < file.txt
# Or
$ wc -l file.txt
# Output:
# 10 file.txt
# OR
# Method 2 - 'sed'
# 'sed' is a stream editor that can be used to perform basic text transformation
# of an input file.
# This command is mostly used for find-and-replace functionality and
# can also be used to find the number of lines of a specified file.
$ sed -n '=' file.txt
# Output:
# 1
# 2
# 3
# 4
# 5
# Or
# sed -n '$=' which gives the overall number of lines
$ sed -n '$=' file.txt
# Output:
# 5