Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash count lines

wc -l
Comment

count new lines bash

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

count lines in bash script


# 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 :: git submodule push current branch to master 
Shell :: src refspec master does not match any 
Shell :: install visual studio on ubuntu 
Shell :: run bash script linux with sudo password 
Shell :: pm2 logs log time 
Shell :: Flatpak in linux 
Shell :: how to install certbot on ubuntu 
Shell :: postinstall docker 
Shell :: delete command in linux 
Shell :: make pm2 auto-boot at server restart 
Shell :: how to install node using nvm 
Shell :: android debug keystore windows 
Shell :: storage setup in termux 
Shell :: helm docker generate doc 
Shell :: linux hex to dec 
Shell :: kube log 
Shell :: how to create new branch 
Shell :: bash change case 
Shell :: gui for ubuntu server 
Shell :: aos animate install 
Shell :: powershell allow execution 
Shell :: install screen recorder linux 
Shell :: npm install express 
Shell :: This repository has moved 
Shell :: gulp install 
Shell :: How do I undo the most recent local commits in Git? 
Shell :: throw exception powershell 
Shell :: concatenate in bash the output of two commands 
Shell :: install kubectl on linux 
Shell :: update database syntaxn using nuget package 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =