Displaying number of lines from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Displaying number of lines from file
# 1  
Old 12-09-2008
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  
Old 12-09-2008
Code:
p=`wc -l < text file`
echo "$p"

# 3  
Old 12-09-2008
but p returning values with leading space. how could i avoid those leading space?
# 4  
Old 12-09-2008
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  
Old 12-09-2008
# 6  
Old 12-09-2008
Quote:
Originally Posted by shivanete
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..
# 7  
Old 12-10-2008
Quote:
Originally Posted by shivanete
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding user name to file, and then displaying new line number

Hi all - I'm completely stumped by a script I'm working on... The short version is I have a file called 'lookup' and in it are hundreds of names (first and last). I have a script that basically allows the user to enter a name, and what I need to have happen is something like this: Record... (8 Replies)
Discussion started by: sabster
8 Replies

2. Shell Programming and Scripting

Displaying a number in binary using perl

printf FH2" 3'b%b : begin\n",$i; where i is an integer in the loop is displaying 3'b1 : begin expected output was 3'b001 : begin (1 Reply)
Discussion started by: dll_fpga
1 Replies

3. Shell Programming and Scripting

Displaying lines of a file which have the highest number?

Hello Wondering if anybody may be able to advise on how I can filter the contents of the following file: <object_name>-<version> <Instance> GM_GUI_code.fmb-4 1 GM_GUI_code.fmb-5 1 GM_GUI_code.fmx-4 ... (7 Replies)
Discussion started by: Glyn_Mo
7 Replies

4. Homework & Coursework Questions

Displaying specific lines from a CSV file

1. The problem statement, all variables and given/known data: Display from a csv file, birthdays that occur today. If there are no birthdays today, the next one in the year. 2. Relevant commands, code, scripts, algorithms: The csv file is ordered from older to younger (ie. the most recent... (8 Replies)
Discussion started by: Adzi
8 Replies

5. Shell Programming and Scripting

Number lines of file and assign variable to each number

I have a file with a list of config files numbered on the lefthand side 1-300. I need to have bash read each lines number and assign it to a variable so it can be chosen by the user called by the script later. Ex. 1 some data 2 something else 3 more stuff which number do you... (1 Reply)
Discussion started by: glev2005
1 Replies

6. Shell Programming and Scripting

Displaying lines of a file where the second field matches a pattern

Howdy. I know this is most likely possible using sed or awk or grep, most likely a combination of them together, but how would one go about running a grep like command on a file where you only try to match your pattern to the second field in a line, space delimited? Example: You are... (3 Replies)
Discussion started by: LordJezoX
3 Replies

7. Shell Programming and Scripting

Displaying Number with printf

I am trying to display a number with commas printf "%d\n" 323232 printf "%d\n" 1234567 I want the output to be: 323,232 1,234,567 I tried to change %d to other formats and could find the solution. any idea? (7 Replies)
Discussion started by: ynixon
7 Replies

8. UNIX for Dummies Questions & Answers

Displaying Number with printf

I am trying to display a number with commas printf "%d\n" 323232 printf "%d\n" 1234567 I want the output to be: 323,232 1,234,567 I tried to change %d to other formats and could find the solution. any idea? (7 Replies)
Discussion started by: ynixon
7 Replies

9. UNIX for Dummies Questions & Answers

Displaying specific lines in a file.

I'm trying to figure out how to display a certain line in a text file. I keep getting references to Tail and Head, and I know how these work, but i'm lost on how to find say the third out of the five lines and display only that. I thought maybe grep could help, but that doesn't seem likely. ... (3 Replies)
Discussion started by: MaestroRage
3 Replies

10. UNIX for Dummies Questions & Answers

help with displaying certain lines

suppose i have a file which contains this: 00 07 * * * /home/production/bin/xxx.ksh 00 08 * * * /home/production/bin/xyz.ksh 00 12 * * * /home/production/bin/tuv.ksh 30 06 * * * /home/production/bin/cde.ksh 30 10 * * * /home/production/bin/put.ksh 00 01 * * * /home/production/bin/lik.sh ... (3 Replies)
Discussion started by: rooh
3 Replies
Login or Register to Ask a Question