How do I include the file being compared into calculation?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I include the file being compared into calculation?
# 15  
Old 12-28-2011
how can I print off the filename as the first line ?
# 16  
Old 12-28-2011
Code:
nawk -F, 'NR==FNR{a[$1OFS$2OFS$3]++;next} a[$1OFS$2OFS$3]{b[$1OFS$2OFS$3]++} v!~FILENAME{f=f" "FILENAME;v=FILENAME}
END{print f;for(i in b){if(b[i]-1){print i"\t\t"b[i]}else{print "NEW :"i} } }' OFS=,20111125.csv *.csv | sort

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 17  
Old 12-28-2011
that just prints off all the filenames, not what I wanted
# 18  
Old 12-28-2011
Which filename do you want?

May be this?

Code:
nawk -F, 'NR==FNR{f=FILENAME;a[$1OFS$2OFS$3]++;next} a[$1OFS$2OFS$3]{b[$1OFS$2OFS$3]++}
END{print f;for(i in b){if(b[i]-1){print i"\t\t"b[i]}else{print "NEW :"i} } }' OFS=, 20111125.csv *.csv | sort

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 19  
Old 12-28-2011
20111125.csv as the first line
# 20  
Old 12-28-2011
Check my previous post!

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 21  
Old 12-28-2011
Bombs out at line 2
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with awk percentage calculation from a file

i have a file say test with the below mentioned details Folder Name Total space Space used /test/test1 500.1GB 112.0 GB /test/test2 3.2 TB 5TB /test/test3 3TB 100GB i need to calculate percentage of each row based on total space and space used and copy... (9 Replies)
Discussion started by: venkitesh
9 Replies

2. Shell Programming and Scripting

Get file name which include the current date

Hi, I'm trying to get the name of a file that has the current date in the name. The filename is on the form A<current date>01.DC, for example A2012110501.DC I have this script so far date +%y%m%d D=$(date +%y%m%d) N=A20$D echo $N N2={$N}01.DC echo $N2 And gets the following... (12 Replies)
Discussion started by: Immelstorn
12 Replies

3. Shell Programming and Scripting

Need to include two more columns in the file using awk

Hi, I have a input file with many records as below: 1J4RR4GG0BC508200 68646 1 N M i want my output file to be like with columns included dgismdh and timestamp : Example: 1J4RR4GG0BC508200 68646 1 N M dgismdh 2012-02-21 07:22:25.98591 How to do it.can we do using awk? Pls help. (6 Replies)
Discussion started by: sonam273
6 Replies

4. Shell Programming and Scripting

math calculation for a txt file

Hi All, I have a text file which is only one column. I want to multiply all these values in file1.txt by 0.01 and get the output.txt file1.txt 65 85 90 ... output.txt 0.65 0.85 0.90 ... Thanks. Please use code tags when posting data and code samples! (2 Replies)
Discussion started by: senayasma
2 Replies

5. Shell Programming and Scripting

Calculation from a file

Hi , I have a file with below format 6/1/200618:00:011348797339524635352499218493964052971 6/1/200617:00:011348672070311735349025833693964052971 6/1/200616:00:011348546711070035345679259193964052971 I want a output as below 6/1/200618:00:011348797339524635352499218493964052971... (1 Reply)
Discussion started by: manojit123
1 Replies

6. Shell Programming and Scripting

include file name to extracted files

I've written the script below to merge only .txt files that exist in one directory into one huge .txt file and ignore other files with other extensions. now the result is one huge .txt file with all the contents of other .txt files how can i add a File Name as a comment before each file? ... (12 Replies)
Discussion started by: miss_dodi
12 Replies

7. Shell Programming and Scripting

File Size calculation with AWK

Hello Friends, Im calculating file sizes with below AWK script. I do this before some spesific files are transferred. I run the script it works but after several running it stuck with a limit of 2147483647 (2 Gbytes -1 byte) and cant exceed this. Something is wrong and I can't proceed, would... (1 Reply)
Discussion started by: EAGL€
1 Replies

8. UNIX for Dummies Questions & Answers

calculation on a large file

Trying to do some simple maths on a large file. Excel works fine but I have 1 million entries: If the difference between a number in column 2 and the one above it is more than 100 the insert a new line 8 4001 4100 8 4101 4200 8 4201 4300 8 15901 16000 8 15910 ... (1 Reply)
Discussion started by: dr_sabz
1 Replies

9. Programming

Not able to compile Pro*c file due - give errors and points to /usr/include/.. file

I am trying to compile the pro*C file but gives errors. It says it encountered "std" while it was expecting ; , = ( $ $ORACLE_HOME/bin/proc tradewind/dataaccess/Blob.pcc Pro*C/C++: Release 10.2.0.3.0 - Production on Fri May 9 11:10:54 2008 Copyright (c) 1982, 2005, Oracle. All rights... (0 Replies)
Discussion started by: shafi2all
0 Replies
Login or Register to Ask a Question