The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Displaying specific lines in a file. MaestroRage UNIX for Dummies Questions & Answers 3 02-05-2008 04:57 PM
How to find number of lines in a file somesh_p Shell Programming and Scripting 2 12-19-2007 09:15 PM
total number of lines in a file Raynon Shell Programming and Scripting 9 10-04-2007 10:13 AM
cut a number of lines out of a file networkfre@k Shell Programming and Scripting 1 12-09-2005 01:46 AM
Need ls to show number of lines in each file GMMike UNIX for Dummies Questions & Answers 1 11-19-2004 05:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-09-2008
shivanete shivanete is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 14
Displaying number of lines from file

Hi,

I am using below command to display the number of line, but its returning no of lines along with file name.

But i want only no of line in the variable p.

Please help me on this?

p=`wc -l "text file"`
echo "$p"
  #2 (permalink)  
Old 12-09-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Code:
p=`wc -l < text file`
echo "$p"
  #3 (permalink)  
Old 12-09-2008
shivanete shivanete is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 14
but p returning values with leading space. how could i avoid those leading space?
  #4 (permalink)  
Old 12-09-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
It does show no leading blank in my case after adding the redirection. You can always just pipe it into for example:
Code:
..| awk '{print $1}'
or something.
  #5 (permalink)  
Old 12-09-2008
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,878
Quote:
Originally Posted by shivanete View Post
but p returning values with leading space. how could i avoid those leading space?
Code:
nl=$(($(wc -l<filename)))

Last edited by radoulov; 12-10-2008 at 04:41 AM..
  #6 (permalink)  
Old 12-09-2008
spirtle spirtle is offline
Registered User
  
 

Join Date: Jun 2008
Location: Scotland
Posts: 150
Does this help?
Remove space obtained from oracle
  #7 (permalink)  
Old 12-10-2008
Leion Leion is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 16
Quote:
Originally Posted by shivanete View Post
Hi,

I am using below command to display the number of line, but its returning no of lines along with file name.

But i want only no of line in the variable p.

Please help me on this?

p=`wc -l &quot;text file&quot;`
echo &quot;$p&quot;
you may want to consider using this command instead:
Code:
 sed -n '$=' filename
Closed Thread

Bookmarks

Tags
shell script, shell scripting, shiva, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0