Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash count lines

wc -l
Comment

count new lines bash

command | wc -l  
wc -l < some_file.txt
Comment

bash: count number of lines


# 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

Comment

PREVIOUS NEXT
Code Example
Shell :: read lines shell script 
Shell :: how to recover last commit git 
Shell :: remove in terminal 
Shell :: CMake: unsupported GNU version -- gcc versions later than 8 are not supported 
Shell :: enable systemd 
Shell :: kali linux gui for wsl2 
Shell :: change folder permissions to public linux 
Shell :: pushing image to docker hub 
Shell :: download spyder without anaconda 
Shell :: bash get result of function 
Shell :: bash check if string ends with slash 
Shell :: copy files from certain date linux 
Shell :: dependencies needed for kernel edit linux amd64 
Shell :: get from match to end of file 
Shell :: centos 7 install docker compose 
Shell :: how to cancel a scheduled shutdown or reboot with shutdown command 
Shell :: git merge master into branch 
Shell :: vim discard changes and quit command 
Shell :: compiling c 
Shell :: kubernetes command kubectl 
Shell :: restart bluetooth kali 
Shell :: convert dos to unix 
Shell :: rmdir command 
Shell :: current directory makefile 
Shell :: print variable in bash 
Shell :: how to git push in jenkins pipeline 
Shell :: git diff between one file 
Shell :: install docker on linux debian 
Shell :: git config set email 
Shell :: symbolic link linux 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =