Ability to store number of rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ability to store number of rows
# 1  
Old 03-28-2007
Ability to store number of rows

Hi,

I am creating a korn shell script and i'm trying to find out what the total number of rows are in a specific text file and i need to store that number in a variable withing the script.

i know wc -l gives you the number, but it also has some leading spaces and then writes out the file name as well. All i need is the actual number or rows.

Also, i believe awk has the ability to return this value, but not sure how to store the value in a variable.

thanks
scott
# 2  
Old 03-28-2007
Some ways to do this - the "lines" variable will have the line count
Code:
wc -l filename | read dummy lines
lines=$(sed -n '$=' filename)
lines=$(awk 'END{ print NR}' filename)

# 3  
Old 03-29-2007
Code:
lines=$( wc -l < filename )

This User Gave Thanks to anbu23 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to count number of rows

Hi, I need a solaris shell script to read multiple files and count number of unique name rows(strings) from those files. The input and output should be like this Input: file 1 abc cde abc ... (9 Replies)
Discussion started by: ssk250
9 Replies

2. Shell Programming and Scripting

extracting number of rows

if > wc -l data.txt > 100 (meaning there are 100 rows) i want to assgn 100 as n so that if i do >echo n it would give me 100 Thanks (5 Replies)
Discussion started by: johnkim0806
5 Replies

3. Programming

store information in hash and display number of keys.

I am trying to store this information (info and number) in hash. number is the key and info is value in a hash.i shown my code below. #!/usr/bin/perl use warnings; use strict; use XML::LibXML::Reader; my $file;open $file, 'formal.xml'); my $reader =... (0 Replies)
Discussion started by: veerubiji
0 Replies

4. Shell Programming and Scripting

How to store a number along with the sign

If I use the below cut -c37-48, the minus sign does not get appended to the number, as the sign is in the 36th Position. But, If I use cut -c36-48, the minus sign appears infront of the number, but for positive numbers, it throws an error. How can this be resolved.. (7 Replies)
Discussion started by: Haimanti
7 Replies

5. Shell Programming and Scripting

awk number rows from 1 to 3 in file

I have a file with the following format, i need to change de field9 each 3 rows to renumber field9 with gpo1, gpo2, gpo3. I need to use awk Original file field1 field2 field3 field4 field5 field6 field7 field8 gpo3 field1 field2 field3 field4 field5 ... (3 Replies)
Discussion started by: robonet
3 Replies

6. Shell Programming and Scripting

how to add the number of row and count number of rows

Hi experts a have a very large file and I need to add two columns: the first one numbering the incidence of records and the another with the total count The input file: 21 2341 A 21 2341 A 21 2341 A 21 2341 C 21 2341 C 21 2341 C 21 2341 C 21 4567 A 21 4567 A 21 4567 C ... (6 Replies)
Discussion started by: juelillo
6 Replies

7. Shell Programming and Scripting

Store number in a directory

hi all, this is some code in c...i want to write script for this... for(i=0;i<10;i++) { store i in backup directory; } (1 Reply)
Discussion started by: AbhijitIT
1 Replies

8. UNIX for Dummies Questions & Answers

Using GREP/AWK to extract a number and store it as a variable

Hello, I have a question regarding the awk command. Here is the line I need to grep: 1 F= -.13250138E+03 E0= -.13249556E+03 d E =-.174650E-01 mag= 35.2157 Instead of displaying the number in red I would like to store it as a variable such as X. Is there a way to do this? Thanks for any... (3 Replies)
Discussion started by: modey3
3 Replies

9. Shell Programming and Scripting

Capturing a number at the end of line and store it as variable

Hello, Would someone guide me on how to write a shell script the would search for a phone no using at the end text file using sed or awk and store it in a varaible or print it. The text file is in this form text or numbers in first line text or numbers in second line . . . Firsname... (6 Replies)
Discussion started by: amuthiga
6 Replies

10. UNIX for Advanced & Expert Users

What is the Maximum number of characters that i can store in a variable?

Hi, Can any one tell me, what is the maximum number of characters that can be stored in a variable? Thanks in Advance, Shan (9 Replies)
Discussion started by: pcshan
9 Replies
Login or Register to Ask a Question