Sponsored Content
Top Forums Shell Programming and Scripting Compare file1 header count with file2 line count Post 302890344 by pone2332 on Wednesday 26th of February 2014 12:39:50 PM
Old 02-26-2014
Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another script that does a validation check to make sure the wc -l for the detail is the same as the count in the header.

Questions: Is the exising code the best approach? If they match I need to continue on and execute another script.

File1(Header File) Content:
FTB2013-10-10FTB_TRIG_DET_FILE_FPRS201310101239.TXT 000000004

File 2 (Detail File): wc -l should equal 4 in this case.

Code:
HDR_count=$(cat /apps/fmp/ftp/Incoming/FPRS/DC/FTB_TRIG_HDR* | awk '{print $2}'  | sed 's/^0*//' )
DET_count=$(wc -l /apps/fmp/ftp/Incoming/FPRS/DC/FTB_TRIG_DET* )
if [ ${HDR_count} -ne ${DET_count} ]
then
    echo
        echo "HDR count[ ${HDR_count} ] net equal to DET count [ ${DET_count} ]"
        exit 3
fi

---------- Post updated at 12:39 PM ---------- Previous update was at 08:50 AM ----------

Hello All,

If other examples of this are already documented please let me know and I will take a look. Thanks again.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk Compare f1,f2,f3 of File1 with f1 of File2

I have an Awk string-compare problem and have searched the internet and forums for a solution i could use but cannot find a solution i understand to make work with my particular problem: I need to compare (field1 field2 field3 of File1) against (field1 of File2) and if they match print out... (6 Replies)
Discussion started by: RacerX
6 Replies

2. Shell Programming and Scripting

Awk Compare File1 File2 on f2

I'm trying to compare two files using AWK, where if field2 of both files match, replace field1 of file1 with field1 of file2 and if there is no match just print the line of file1. file1.txt (has empty first field) :ABBATOM:B:H:1992 :ABBA TROJAN:B:H:1993 :ABBES FIRST HOPE:B:M:1997 :ABBEYS... (4 Replies)
Discussion started by: RacerX
4 Replies

3. Shell Programming and Scripting

Compare multiple fields in file1 to file2 and print line and next line

Hello, I have two files that I need to compare and print out the line from file2 that has the first 6 fields matching the first 6 fields in file1. Complicating this are the following restrictions 1. file1 is only a few thousand lines at most and file2 is greater than 2 million 2. I need to... (7 Replies)
Discussion started by: gillesc_mac
7 Replies

4. Shell Programming and Scripting

Shell script to count number of ~ from each line and compare with next line

Hi, I have created one shell script in which it will count number of "~" tilda charactors from each line of the file.But the problem is that i need to count each line count individually, that means. if line one contains 14 "~"s and line two contains 15 "~"s then it should give an error msg.each... (3 Replies)
Discussion started by: Ganesh Khandare
3 Replies

5. UNIX for Dummies Questions & Answers

if matching strings in file1 and file2, add column from file1 to file2

I have very limited coding skills but I'm wondering if someone could help me with this. There are many threads about matching strings in two files, but I have no idea how to add a column from one file to another based on a matching string. I'm looking to match column1 in file1 to the number... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

6. Shell Programming and Scripting

look for line from FILE1 at FILE2

Hi guys! I'm trying to write something to find each line of file1 into file2, if line is found return YES, if not found return NO. The result can be written to a new file. Can you please help me out? FILE1 INPUT: WATER CAR SNAKE (in reality this file has about 600 lines each with a... (2 Replies)
Discussion started by: demmel
2 Replies

7. UNIX for Dummies Questions & Answers

File Row Line Count without Header Footer

Hi There! I am saving the file count of all files in a directory to an output file using: wc -l * > FileCount.txt I get: 114 G4SXORD 3 G4SXORH 0 G4SXORP 117 total But this count includes header and footer. I want to subtract 2 from the count and get ... (7 Replies)
Discussion started by: gagan8877
7 Replies

8. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

9. Shell Programming and Scripting

Compare and find records of file1 not in file2

hi.. i am using solaris system and ksh and using nawk to get records of file1 not in file2(not line by line comparison). code i am using is nawk 'NR==FNR{a++} !a {print"line:" FNR"->" $0} ' file2 file1 same command with awk runs perfectly on darwin kernel(mac) but in solaris it does line by... (2 Replies)
Discussion started by: Abhiraj Singh
2 Replies

10. UNIX for Dummies Questions & Answers

Compare file1 and file2, print matching lines in same order as file1

I want to print only the lines in file2 that match file1, in the same order as they appear in file 1 file1 file2 desired output: I'm getting the lines to match awk 'FNR==NR {a++}; FNR!=NR && a' file1 file2 but they are in sorted order, which is not what I want: Can anyone... (4 Replies)
Discussion started by: pathunkathunk
4 Replies
goaccess(1)							   User Manuals 						       goaccess(1)

NAME
goaccess - fast web log analyzer and interactive viewer. SYNOPSIS
goaccess [-f input-file ] [-c] [-e] [-a] DESCRIPTION
goaccess is a free (GPL) real-time web log analyzer and interactive viewer that runs in a terminal in *nix systems. It provides fast and valuable HTTP statistics for system administrators that require a visual server report on the fly. First it will parse the web log file, then it will collect data from the parsed file and it will display it to the console or the X terminal. The collected information will be displayed to the user in a visual/interactive window. The collected information includes: General Statistics: Total number of valid requests, Total number of invalid requests, Total time to analyze the data, Total unique visitors, Total unique requested files, Total unique static files (css,ico,jpg,js,swf,gif,png) Total unique HTTP referrers (URLs), Total unique 404s (not found), Size of the parsed log file, Total bandwidth consumption. Unique visitors: HTTP requests having the same IP, same date and same agent will be considered a unique visit. (including crawlers). {Detail view} is available for this module Requested files The totals are based on unique requested files. This is based on the premise that HTTP requests having the same IP, same date and same agent will be considered a unique visit. {Detail view} is available for this module Requested static files The totals are based on unique requested files. Includes files such as: jpg, css, swf, js, gif, png etc. Unique requests are based on the premise that HTTP requests having the same IP, same date and same agent will be considered a unique visit. {Detail view} is available for this module Referrers URLs The URL where the request came from. Totals are not based on the above premise, but instead, based on the total number of requests. {Detail view} is available for this module 404 or Not Found The total number is based on total requests. {Detail view} is available for this module Operating Systems The total number is based on unique visitors. {Detail view} is available for this module Browsers The total number is based on unique visitors. {Detail view} is available for this module Hosts The total number is based on total requests. {Detail view} is available for this module. {Detail view} for each IP can display extra information for the particular host, including reverse dns, and geolocation of the IP. HTTP Status Codes Totals are based on total requests. {Detail view} is available for this module Referring Sites This module will display only the host but not the whole URL. The total number is based on total requests. {Detail view} is avail- able for this module Keyphrases This module will report keyphrases used on Google search, Google cache, and Google translate. The total number is based on total requests. {Detail view} is available for this module OPTIONS
-f input-file Path to input log file. -c Prompt date and log format configuration window. -e Exclude an IP from being counted under the HOST module. -a Enable a list of User-Agents for the selected host. CUSTOM LOG
/DATE FORMAT GoAccess can parse virtually any web log format. Predefined options include, Common Log Format (CLF), Combined Log Format (XLF/ELF), including virtual host and W3C format (IIS). GoAccess allows any custom format string as well. There are two ways to configure the log format. The easiest is to run GoAccess with -c to prompt a configuration window. Otherwise, it can be configured under ~/.goaccessrc. date_format The date_format variable followed by a space, specifies the log format date containing any combination of regular characters and special format specifiers. They all begin with a percentage (%) sign. See http://linux.die.net/man/3/strftime log_format The log_format variable followed by a space, specifies the log format string. %d date field matching the date_format variable. %h host (the client IP address, either IPv4 or IPv6) %r The request line from the client. %s The status code that the server sends back to the client. %b The size of the object returned to the client. %R The "Referer" HTTP request header. %u The User-Agent HTTP request header. %^ Ignore this field. INTERACTIVE MENU
F1 Main help. F5 Redraw main window. q Quit the program or the current {detail view} (window). o Open a {detail view} for the current active module. c set or change scheme color. TAB Forward iteration of modules. Starts from current active module. SHIFT + TAB Backward iteration of modules. Starts from current active module. RIGHT ARROW Open a {detail view} for the current active module. 0-9 Activate module so the user can open a {detail view} with either ^o^ or ^RIGHT ARROW^. SHIFT + 0-9 Activate module above 10. s Sort unique visitors by date. This will only work on the Unique visitors module(1). S Sort unique visitors by hits. This will only work on the Unique visitors module(1). / Search forward on any {detail view} window for the occurrence of typed pattern. n Find the position of the next occurrence on any {detail view} window. t Move to the first item or top of screen. b Move to the last item or bottom of screen. EXAMPLES
The simplest and fastest usage would be: # goaccess -f access.log That will generate an interactive text-only output. To generate an HTML report: # goaccess -f access.log -a > report.html To generate full statistics we can run GoAccess as: # goaccess -f access.log -a The -a flag indicates that we want to process an agent-list for every host parsed. The -c flag will prompt the date and log format config- uration window. Only when curses is initialized. Now if we want to add more flexibility to GoAccess, we can do a series of pipes. For instance: If we would like to process all access.log.*.gz we can do: # zcat access.log.*.gz | goaccess OR # zcat -f access.log* | goaccess Another useful pipe would be filtering dates out of the web log The following will get all HTTP requests starting on 05/Dec/2010 until the end of the file. # sed -n '/05/Dec/2010/,$ p' access.log | goaccess -a If we want to parse only a certain time-frame from DATE a to DATE b, we can do: sed -n '/5/Nov/2010/,/5/Dec/2010/ p' access.log | goaccess -a Note that this could take longer time to parse depending on the speed of sed. Also, it is worth pointing out that if we want to run GoAccess at lower priority, we can run it as: # nice -n 19 goaccess -f access.log -a NOTES
On each {detail view} window, the total number of items is 300. Piping a log to GoAccess will disable the real-time functionality. This is due to the portability issue on determining the actual size of STDIN. However, a future release *might* include this feature. BUGS
If you think you have found a bug, please send me an email to goaccess@prosoftcorp.com AUTHOR
Gerardo Orellana <goaccess@prosoftcorp.com> For more details about it, or new releases, please visit http://goaccess.prosoftcorp.com Linux JUNE 2012 goaccess(1)
All times are GMT -4. The time now is 06:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy