File Count and FileName


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Count and FileName
# 1  
Old 01-15-2015
File Count and FileName

Hi I have a set of files in one directory like below
Code:
FIN_TASK1.csv
FINA_TASK2.csv
FIN_TASK3.csv

.

I want a command to print the count in each file and the correspong file name into one file.My expected output is given below

Code:
cat filcount.txt
 2 "FIN_TASK1.csv"
      4 "FIN_TASK2.csv"
     12 "FIN_TASK3.csv"

Also in another folder I have similar file as in the above output.So I want to compare this two files by matching the file name and see the % of difference in the count.The file name in both the files can be in different order.

Code:
cat errorcount.csv
4 "FIN_TASK3.csv"
8 "FIN_TASK1.csv"
12 "FIN_TASK2.csv"


so if
# 2  
Old 01-15-2015
# 3  
Old 01-15-2015
Thanks for the reply.

I want the count in each file instead of file size
# 4  
Old 01-15-2015
Quote:
Originally Posted by ginrkf
Hi I have a set of files in one directory like below
Code:
FIN_TASK1.csv
FINA_TASK2.csv
FIN_TASK3.csv

.

I want a command to print the count in each file and the correspong file name into one file.My expected output is given below

Code:
cat filcount.txt
 2 "FIN_TASK1.csv"
      4 "FIN_TASK2.csv"
     12 "FIN_TASK3.csv"

Also in another folder I have similar file as in the above output.So I want to compare this two files by matching the file name and see the % of difference in the count.The file name in both the files can be in different order.

Code:
cat errorcount.csv
4 "FIN_TASK3.csv"
8 "FIN_TASK1.csv"
12 "FIN_TASK2.csv"

so if
Hello ginrkf,

Assuming like your file may have spaces in starting, not sure about your query of percentage differences, following solution
can be taken as a start up. Please let us know exact desired output for same we may help you.
Code:
awk 'FNR==NR{X[$2]=$1;next} {gsub(/^[[:space:]]+/,Y,$0);} ($2 in X){C=X[$2] > $1?X[$2] - $1:$1 - X[$2];print $2 OFS C}' errorcunt filcount

Output will be as follows.
Code:
"FIN_TASK1.csv" 6
"FIN_TASK2.csv" 8
"FIN_TASK3.csv" 8

Note: I have checked here the values like we should not get differences in minus so let us know how we need to take difference
also is it always filcount-errorcunt or it can be bi directional too.


Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

2. Shell Programming and Scripting

To count underscore in filename

Hi All I have a filename like below adsf_ghjt_kop_pol.csv Can you please get me a command for counting the number of underscore in the filename. In the above filename I should get output as 3, since the file name is having three underscore (5 Replies)
Discussion started by: ginrkf
5 Replies

3. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

4. Shell Programming and Scripting

Filename pattern count

Hi I have the following files in a directory - ds_pl_W_Test ds_pl_list_Test ds_pl_list_Test ds_pl_listl_Test ds_pl_file_Test ds_pl_xx_Test I would like to count the number files in the directory that contain the word "list" I tried the following but it returns zero - ... (3 Replies)
Discussion started by: Prega
3 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

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

7. Shell Programming and Scripting

Getting Sum, Count and Distinct Count of a file

Hi all this is a UNIX question. I have a large flat file with millions of records. col1|col2|col3 1|a|b 2|c|d 3|e|f 3|g|h footer**** I am supposed to calculate the sum of col1 1+2+3+3=9, count of col1 1,2,3,3=4, and distinct count of col1 1,2,3=c3 I would like it if you avoid... (4 Replies)
Discussion started by: singhabhijit
4 Replies

8. Shell Programming and Scripting

gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
Discussion started by: timj123
6 Replies

9. UNIX for Dummies Questions & Answers

Count caraters on filename

Hello people. I need some help to do this: I've got some files that i need to count the caracters of filenames. 20080209_2000591574_237004076372.xml 20080202_1360584_267002636042.xml The minimum is 15 . If some file with less must move them to another directory. Obviously these... (3 Replies)
Discussion started by: osramos
3 Replies

10. UNIX for Dummies Questions & Answers

How to count the record count in an EBCDIC file.

How do I get the record count in an EBCDIC file on a Linux Box. :confused: (1 Reply)
Discussion started by: oracle8
1 Replies
Login or Register to Ask a Question