script to take row count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to take row count
# 1  
Old 10-22-2008
script to take row count

hi

i am pretty new to unix .i am ETL guy
I need a unix script to take row count of a file and write it to another file
the problem with wc-l is it include filename also
wc -l abc.dat
will give me like 1000 abc.dat
i just want 1000 to be written
can u just take 2 min to write a simple script for me
# 2  
Old 10-22-2008
You don't need a script for that:
Code:
awk 'END{print NR}' file > new.file

# 3  
Old 10-22-2008
thnaks

thank buddy u r great
# 4  
Old 10-23-2008
Hi Danmero,

I have used the following command to count the rows. It works fine for small file which has column sort.
awk 'END{print NR}' file > new.file

but unfortunetly my file has 540 column seperated with ~ delimiter. While using this command for the file it shows error. "record .... too long"
# 5  
Old 10-23-2008
if wc is working fine then you use line the below...


Code:
wc -l abc.dat|awk '{print $1}' >newfile

# 6  
Old 10-23-2008
wc -l < abc.dat
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Row Count in .csv file

Hi, I have to find the count of rows starting with "E," in given a.csv file . Sample Data File. E,2333AED,A,MC3,25,31-MAY-18 E,2333AED,A,MC3,25,31-MAY-18 CYMC3 25AED 0000 E,2333CZK,A,MC3,25,31-MAY-18 CYMC3 25CZK 0000 E,2333EUR,A,MC3,25,31-MAY-18... (3 Replies)
Discussion started by: Prabhakar Y
3 Replies

2. UNIX for Advanced & Expert Users

row count

Hi, I want a row count of a file incliding header and trailer If I do cat Filename | wc -l then I am only getting the row count excluding the header and trailer Buit I want the row count including Header and trailer Please help Many thanks in advance, Pragyan (3 Replies)
Discussion started by: prarat
3 Replies

3. Shell Programming and Scripting

Count the number or row with same value in a column

This is the source file, we called it errorlist.out 196 server_a server_unix_2 CD 196 server_b server_win_1 CD 196 server_c server_win_2 CD 196 server_bd server_unix_2 CD 196 server_d server_unix_2 CD 196 server_es server_win_1 CD 196 ... (14 Replies)
Discussion started by: sQew
14 Replies

4. Shell Programming and Scripting

To count distinct fields in a row

I have . dat file which contains data in a specific format: 0 3 892 921 342 1 3 921 342 543 2 4 817 562 718 765 3 3 819 562 717 761 i need to compare each field in a row with another field of the same column but different row and cont the... (8 Replies)
Discussion started by: Abhik
8 Replies

5. Shell Programming and Scripting

Count the delimeter from a file and delete the row if delimeter count doesnt match.

I have a file containing about 5 million rows, in the file there are some records which has extra delimiter at random position. (we dont know the positions), now we have to Count the delimeter from each row and if the count of delimeter is not matching then I want to delete those rows from the... (5 Replies)
Discussion started by: Akumar1
5 Replies

6. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

7. UNIX for Dummies Questions & Answers

Script to get Row Count of ZIP Files

Hi, I have some data files in a zipped format.(eg: aa.gz).I would like to know the number or rows in each zip file(May be populate the file name and line numbers into a text file).I know the commands wc -l and gunzip,.But how I will create a shell script for this to extract each files and get... (5 Replies)
Discussion started by: abhilash_menon
5 Replies

8. Shell Programming and Scripting

row count of 60 files in one file

hi all plz some unix guy help me in this i have 60 files which will have some records i want to find the total number of records in all the 60 files like file1 has 60 and file2 has 70 record i want to sum all these and find total row count in 60 files (5 Replies)
Discussion started by: er_zeeshan05
5 Replies

9. UNIX for Dummies Questions & Answers

row count but only number part

hi i am pretty new to unix .i am ETL guy I need a unix script to take row count of a file and write it to another file the problem with wc-l is it include filename also wc -l abc.dat will give me like 1000 abc.dat i just want 1000 to be written can u just take 2 min to write a simple... (1 Reply)
Discussion started by: er_zeeshan05
1 Replies

10. UNIX for Dummies Questions & Answers

row count of all files with more than 0 byte

Hi, Is there any way to get count number of lines in all files which have more than o bytes in current directory for example : in /user/sri/ there are 3 files abc 0 bytes def 5 bytes ghi 10 bytes i need to get wc -l for all files which have > 0 bytes at a time ..is... (6 Replies)
Discussion started by: sri2005
6 Replies
Login or Register to Ask a Question