LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 07-26-2008, 10:15 AM   #1
BBFeltham
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, 10:18 AM   #2
Nylex
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:

variable=`command`

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 10:22 AM.
 
  


Reply


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 12:35 PM
how to check number of opened handles ruj.sabya Linux - General 2 08-06-2007 08:37 AM
count total number of lines in several files xushi Programming 5 11-12-2005 04:42 PM
Shell Scripting: How to pick lines out of files by line number. Louie55 Programming 3 03-22-2005 06:18 PM
Can't get lines of a file with a Bash script.. barisdemiray Programming 2 08-11-2004 12:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:31 AM.

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