query display number lines or records present in file only numeric value -without filename


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users query display number lines or records present in file only numeric value -without filename
# 1  
Old 07-22-2011
Power query display number lines or records present in file only numeric value -without filename

Hi all
Thanks in advance...........

Please help me for this issue............

I have a file it has 11 records . I used the command like ....
Code:
>$ wc -l file
11 file

I'm getting output like 11 file (no.of records along with filename)

here my requirement is, I want to display only no.of records without filename
like only 11.

can anyone please tell me which command I have to use?

because if I get this no.of records I have to comapre with some outfile
so shall I assign this no.of records to any variable ?

Thanks
Srivani Kolachina

Last edited by Franklin52; 07-22-2011 at 07:06 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-22-2011
try this

Code:
 
wc -l < file

otherwise, use awk, cut,...etc...

---------- Post updated at 12:44 PM ---------- Previous update was at 12:31 PM ----------

Code:
 
grep -c . file

---------- Post updated at 12:44 PM ---------- Previous update was at 12:44 PM ----------

Code:
 
awk '{i++;} END{print i}' file

---------- Post updated at 12:46 PM ---------- Previous update was at 12:44 PM ----------

Code:
 
perl -lane '$i++;END{print $i}'  file

# 3  
Old 07-22-2011
Thanks a lot ....

>$ wc -l < file
11

But I want to assgin this output to any variable?

I'm declaring like below.
Code:
j=wc -l < file
k=wc -l <outfile
 
if [ $j -eq $k ]
then 
  echo " both are same "
else
  echo " not same"
fi

my program is like this ... but it is giving error like
Code:
ex: line 13: -l: command not found
+ k=wc
+ -l
ex: line 14: -l: command not found

but giving the output properly...
can u please tell me y it is giving like this?

Thanks
Srivani

Last edited by Franklin52; 07-22-2011 at 07:06 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 07-22-2011
Code:
j=`wc -l < file`
k=`wc -l <outfile`

use back ticks

or use it like below

Code:
 
j=$(wc -l < file)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

2. Shell Programming and Scripting

Display the Filename and Size of a File

Hello, all! Working in a Bourne shell. What command would list the filename and size of a file if the size of the file had to be bigger than $a and smaller than $b? Output (if $a is 10 bytes and $b is 50 bytes):test1.txt 15 test2.txt 30 test3.txt 50 Thanks, Ann :p (3 Replies)
Discussion started by: LowlyIntern
3 Replies

3. Shell Programming and Scripting

Need unix commands to delete records from one file if the same record present in another file...

Need unix commands to delete records from one file if the same record present in another file... just like join ... if the record present in both files.. delete from first file or delete the particular record and write the unmatched records to new file.. tried with grep and while... (6 Replies)
Discussion started by: msathees
6 Replies

4. UNIX Desktop Questions & Answers

How to display only the lines from a file which do not contain a given number

a. How do I display the content of the file containing what Ive merged using a filter which would display only the lines of the file which don't contain number, for example 3 or 6. (3 Replies)
Discussion started by: herberwz
3 Replies

5. UNIX for Dummies Questions & Answers

To get the lines that are not present in file

Hi I have got two files File1: Row1 Row2 Row3 Row4 File2: Row3 Row4 Now my requirement is search each and every line of file1 in file2 and if the record do not exist in file2 then write that to an output file. Output file should be as below Row1 Row2 (4 Replies)
Discussion started by: sbhuvana20
4 Replies

6. Shell Programming and Scripting

How to only display lines where a field has the highest number?

Hello Wondering if anybody can advise me how I can sort the below file so it only displays lines with the latest versions of an object? As you'll see some of the scripts listed in my file have more than one version number (version number is after the file extension). E.g. cdm_bri.pkb has... (2 Replies)
Discussion started by: Glyn_Mo
2 Replies

7. Solaris

WARNING: filename <not present on Read Only file system>+pkgadd error

Hi when trying to install the package initially that i have created on to the target host, i am getting error as below for all the files/directories during pkgadd. WARNING: filename <not present on Read Only file system> ........... ........... and so on. When i do the second attempt to... (1 Reply)
Discussion started by: kiran.zamre
1 Replies

8. Shell Programming and Scripting

To find the count of records from tables present inside a file.

hi gurus, I am having a file containing a list of tables.i want to find the count of records inside thes tables. for this i have to connect into database and i have to put the count for all the tables inside another file i used the following loop once all the tablenames are inside the file. ... (1 Reply)
Discussion started by: navojit dutta
1 Replies

9. Shell Programming and Scripting

how to display records of file

dear all, supose there is file called myfile.txt and in this file there are two records.. like this way:- myfile.txt records 1 A:B:C:D:E records 2 B:C:A:F:G I have to find A and display output as "in myfile.txt in record1 A has feild 1 and in myfile.txt in record2 A... (2 Replies)
Discussion started by: mishra_sk_in
2 Replies

10. UNIX for Dummies Questions & Answers

display lines after a particular line number

I have a file that has 1k lines and i want to print all the lines after 900th line. an 2)I want to move files f1 ,f2,f3,f4 to p1,p2,p3,p4 Please give me the commands. Thanx in adv. (6 Replies)
Discussion started by: rajashekar.y
6 Replies
Login or Register to Ask a Question