cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Starfighter Starfighter
Starfighter
  • 281 Views

Line Count

Ways to get a count of the number of lines in a file:

1. Using the "wc" command

              $ wc -l  <filename>

 

2. Using "awk"

              $ awk 'END{ print NR }'  <filename>

 

3. Using "sed"

              $ sed -n \$=   <filename>

 

 

Just a little appetizer - nothing heavy!

 

Trevor "Red Hat Evangelist" Chandler
3 Replies
masharma
Mission Specialist
Mission Specialist
  • 260 Views

Thanks for sharing! sed was the new one for me.

Another way is : cat -n <filename> | awk '{print $1}' | tail -1

Tracy_Baker
Starfighter Starfighter
Starfighter
  • 244 Views

Just for fun:

c=0; while read line; do ((c++)); done < <filename>; echo $c

 

Program Lead at Arizona's first Red Hat Academy, est. 2005
Estrella Mountain Community College
Trevor
Starfighter Starfighter
Starfighter
  • 236 Views

Look at ya flexing

Nice!!!!!

Trevor "Red Hat Evangelist" Chandler
Join the discussion
You must log in to join this conversation.