Counting line in text file

This is a discussion on Counting line in text file within the Linux Programming forums, part of the Platform Specific Boards category; ok to count the number of lines in a text file I have to wc -l filename.txt rite? but then ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    68

    Counting line in text file

    ok to count the number of lines in a text file I have to

    wc -l filename.txt rite? but then how do i get it to out put this as an integer?

    it out puts
    linecount filename.txt

    so lets say file.txt has 30 lines it out puts
    30 file.txt how do i get it to out put only 30

    thx
    -Ti22-

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    1. Make it read from stdin (using redirection) so it doesn't print a filename
    2. Use the back-quotes to capture the stdout of a process

    Like so
    Code:
    a=`wc -l < file.txt`
    echo $a

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    dude your really good, how long have u been using linux?
    -Ti22-

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    grep -n .\* in-file > out-file

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting the characters from each word from a text file
    By flipguy_ph in forum C Programming
    Replies: 6
    Last Post: 04-27-2009, 05:56 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  4. reading from text file
    By jamez in forum C Programming
    Replies: 3
    Last Post: 11-30-2005, 06:13 PM
  5. printing out a line from text file..
    By loso44x in forum C Programming
    Replies: 3
    Last Post: 10-22-2005, 01:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21