Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

count lines in files

find . -name '*.php' | xargs wc -l
Comment

how many number of lines in a file


# 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 bash script 
Shell :: git checkout -f 
Shell :: ubuntu turn off screen terminal 
Shell :: bash debug show line numbers 
Shell :: wc powershell 
Shell :: Merge Remote Repository With Local Repository in git command 
Shell :: Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user 
Shell :: How to squash the last n commits together 
Shell :: how to undo git clean -fd command 
Shell :: Checking dependencies BASH 
Shell :: download file via ssh with port 
Shell :: powershell connect to microsoft teams 
Shell :: extract every nth line using sed linux fedora 
Shell :: bash grep all after match 
Shell :: ionic capacitor video player install 
Shell :: composer install from local directory 
Shell :: how to create an alias 
Shell :: which linux 
Shell :: how to run pkg file on mac terminal 
Shell :: tailwindcss 
Shell :: ubuntu move file 
Shell :: convert dos to unix with tr 
Shell :: vim change all spaces to tabs 
Shell :: powershell add line to beginning of file 
Shell :: create new remote branch 
Shell :: create git repository 
Shell :: git diff files only 
Shell :: secure shell 
Shell :: kibana download 
Shell :: download using docker 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =