Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How do I count lines on a file?  (Read 3589 times)

0 Members and 1 Guest are viewing this topic.

sandratz

    Topic Starter


    Rookie
    How do I count lines on a file?
    « on: July 17, 2007, 02:36:15 AM »
    Hello!

    Can you pls tell me how I can count lines from a file and store the numeric value in a variable without including the string part? ???
    I used the wc command but it wasn't useful bse it also stored the string part!
    Example, variable=wc -l myfile, resulted into 5 myfile.

    How can I get it to store only 5?

    Pls help...

    ghostdog74



      Specialist

      Thanked: 27
      Re: How do I count lines on a file?
      « Reply #1 on: July 17, 2007, 08:29:27 AM »
      you can count lines  and get the number of lines in a few ways
      Code: [Select]
      wc -l file | cut -d" " -f1
      wc -l file | awk  '{print $1}'
      awk 'END{print NR}' file
      grep -c . file
      doing homework huh?

      sandratz

        Topic Starter


        Rookie
        Re: How do I count lines on a file?
        « Reply #2 on: July 18, 2007, 12:57:02 AM »
         :D
        Hi and thanks very much for your help!! The code worked!
        It's odd that I lost my dog Scooby a week ago, and now someone with a username - ghostdog helped me out in my homework!

        Thanx again ;)