Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-26-2008, 11:15 AM   #1
LQ Newbie
Registered: Jul 2008
Posts: 4

Rep: Reputation: 0
commands for bash script that handles files of varying number of lines

Need commands for bash schell script that handles files varying in number of lines.
Old 07-26-2008, 11:18 AM   #2
LQ Addict
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You can use wc to get the number of lines in a file (the option -l does this). Edit: you can also store the output of a command in a variable with syntax like this:


For example, to put the number of lines in the file foo in a variable called num_lines, you'd use the following:

num_lines=`wc -l foo`

Last edited by Nylex; 07-26-2008 at 11:22 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl vs. bash code - number of lines noir911 Programming 11 10-07-2011 01:35 PM
how to check number of opened handles ruj.sabya Linux - General 2 08-06-2007 09:37 AM
count total number of lines in several files xushi Programming 5 11-12-2005 05:42 PM
Shell Scripting: How to pick lines out of files by line number. Louie55 Programming 3 03-22-2005 07:18 PM
Can't get lines of a file with a Bash script.. barisdemiray Programming 2 08-11-2004 01:42 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:28 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration