Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

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 :: how to find the which linux am i using through terminal 
Shell :: zsh git aliases 
Shell :: add directory to path on linux 
Shell :: how to cat a file that has spaces 
Shell :: Failed to mount cgroup at /sys/fs/cgroup/systemd: Operation not permitted 
Shell :: check bluetooth radio status bash 
Shell :: check size of folder linux 
Shell :: scp permission denied (publickey) but ssh works 
Shell :: creat a new repository push 
Shell :: github auto close issue 
Shell :: change git repository commmand 
Shell :: docker compose up 
Shell :: grep all lines after first match 
Shell :: Invalid base64-encoded string: number of data characters (221) cannot be 1 more than a multiple of 4 
Shell :: pull down a branch locally 
Shell :: uninstall node arch 
Shell :: docker nodejs 
Shell :: how to reinstall alsa 
Shell :: see all merge conflict git 
Shell :: install npm package globally 
Shell :: git create local branch 
Shell :: git gui 
Shell :: how to upload on github with command 
Shell :: ssh tunnel map 
Shell :: git add ssh key 
Shell :: apt install yarn 
Shell :: git check differences between two projects 
Shell :: how to pull from specific branch 
Shell :: what is remote repository 
Shell :: uninstall django ubuntu 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =