Sponsored Content
Top Forums Shell Programming and Scripting Help with script to read lines from file and count values Post 302517737 by gman2010 on Wednesday 27th of April 2011 03:12:25 PM
Old 04-27-2011
Help with script to read lines from file and count values

Hi, I need some help with a script I'm trying to write. I have a log file containing references to a number of different webservices. I wish to write a script that will list the webservices with a count as to how many times they appear in the log.

An example of the log file content:

Code:
123.23.111.23 - - [10/Apr/2011:23:59:03 +0100] "POST /GetID/Star HTTP/1.0" 503 693 60014262
333.222.111.43 - - [11/Apr/2011:00:00:02 +0100] "POST /SearchAccount_V2/Star HTTP/1.1" 200 1155 462951
111.888.222.44 - - [11/Apr/2011:00:00:02 +0100] "POST /SearchModem_V2/Star HTTP/1.1" 200 1161 993251
777.22.555.33 - - [11/Apr/2011:00:00:04 +0100] "POST /BillingCode/Star HTTP/1.1" 200 778 90597

So on the 1st line I wish to extract GetID, then the script would count how many instances of GetID there are in the log file.

ordinarily I would use the following if I was just wanting to search for a single entry:

grep GetID /opt/Apache/logs/access_log.11-04-2011 | grep wsdl | wc -l

I have a separate file listing all of the webservices (118 in total) that could be an input into the script.

the output file would look something like:

GetID : 345
SearchAccount_V2 : 687
etc etc

many thanks

Last edited by joeyg; 04-27-2011 at 04:21 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn Shell Script - Read File & Search On Values

I am attempting to itterate through a file that has multiple lines and for each one read the entire line and use the value then to search in other files. The problem is that instead of an entire line I am getting each word in the file set as the value I am searching for. For example in File 1... (2 Replies)
Discussion started by: run_unx_novice
2 Replies

2. Shell Programming and Scripting

Help!! Need script to read files and add values by lines...

Hi All, I really need your help. I am a begginner in shell script and I believe this is a very simple issue. I have in my directory, n-files, like 1.dhm, 2.dhm, 3.dhm. These files have 1 column with 1 value per line, like: 1.dhm ------ 10 20 30 40 50 2.dhm ------ 30 50 20 (3 Replies)
Discussion started by: dhuertas
3 Replies

3. UNIX for Dummies Questions & Answers

Read directory files and count number of lines

Hello, I'm trying to create a BASH file that can read all the files in my working directory and tell me how many words and lines are in that file. I wrote the following code: FILES="*" for f in "$FILES" do echo -e `wc -l -w $f` done My issue is that my file is outputting in one... (4 Replies)
Discussion started by: jl487
4 Replies

4. Shell Programming and Scripting

Why does my script only read two lines of a file and not the third

I'm learning about the read command and wrote this little script to read data from a file: readfile() { while read variable; do echo $variable done } readfile < File.txt I have three lines in File.txt; each a single word. The script only echoes the first two lines and drops the... (9 Replies)
Discussion started by: Straitsfan
9 Replies

5. UNIX for Dummies Questions & Answers

Count Number Of lines in text files and append values to beginning of file

Hello, I have 50 text files in a directory called "AllFiles" I want to make a program that will go inside of the "AllFiles" Directory and count the number of lines in each individual text file. Then, the program will calculate how many more lines there are over 400 in each text file and... (7 Replies)
Discussion started by: motoxeryz125
7 Replies

6. Shell Programming and Scripting

Read record from the text file & assign those values to variables in the script

For eg: I have sample.txt file with 4 rows of record like: user1|password1 user2|password2 user3|password3 user4|password4 The username and password is sepsrated by '|' I want to get the 1st row value from the file and assign it to two different variables(username and password) in my... (1 Reply)
Discussion started by: priya001
1 Replies

7. UNIX for Dummies Questions & Answers

Count the lines with the same values in a column and write the output to a file

Hey everyone! I have a tab delimited data set which I want to create an output contained the calculation of number of those lines with a certain value in 2nd and 3rd column. my input file is like this: ID1 1 10M AAATTTCCGG ID2 5 4M ACGT ID3 5 8M ACCTTGGA ID4 5 ... (7 Replies)
Discussion started by: @man
7 Replies

8. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

9. Shell Programming and Scripting

Read a file and replace values in a script

Hi , I have a property file placed in folder /usr/opt/temp/aorc.prop which has values given below . I need to read this file content and replace the node with actual values in a shell script . Each time the script shall replace the node value from the poperty file and execute a cfsend command and... (10 Replies)
Discussion started by: samrat dutta
10 Replies

10. Shell Programming and Scripting

Read file lines and pass line values as arguments.

Dears, Need help to implement below requirement A file (detail.txt)contain : 1st column: Stream 2nd column: PathAddress 3rd column: Counterlimit 4th column: TransactionDateColumn 5th column: DateType 6th column: SleepValue 7th column: Status Need to write a... (1 Reply)
Discussion started by: sadique.manzar
1 Replies
cupsd-logs(5)							    Apple Inc.							     cupsd-logs(5)

NAME
cupsd-logs - cupsd log files (access_log, error_log, and page_log) DESCRIPTION
cupsd(8) normally maintains three log files: access_log to track requests that are submitted to the scheduler, error_log to track progress and errors, and page_log to track pages that are printed. Configuration directives in cupsd.conf(5) and cups-files.conf(5) control what information is logged and where it is stored. ACCESS LOG FILE FORMAT The access_log file lists each HTTP resource that is accessed by a web browser or client. Each line is in an extended version of the so- called "Common Log Format" used by many web servers and web reporting tools: host group user date-time "method resource version" status bytes ipp-operation ipp-status For example: 10.0.1.2 - - [01/Dec/2005:21:50:28 +0000] "POST / HTTP/1.1" 200 317 CUPS-Get-Printers successful-ok-ignored-or-substituted-attributes localhost - - [01/Dec/2005:21:50:32 +0000] "GET /admin HTTP/1.1" 200 0 - - localhost - - [01/Dec/2005:21:50:32 +0000] "POST / HTTP/1.1" 200 157 CUPS-Get-Printers successful-ok-ignored-or-substituted-attributes localhost - - [01/Dec/2005:21:50:32 +0000] "POST / HTTP/1.1" 200 1411 CUPS-Get-Devices - localhost - - [01/Dec/2005:21:50:32 +0000] "GET /admin HTTP/1.1" 200 6667 - - The host field will normally only be an IP address unless you have enabled the HostNameLookups directive in the cupsd.conf file or if the IP address corresponds to your local machine. The group field always contains "-". The user field is the authenticated username of the requesting user. If no username and password is supplied for the request then this field contains "-". The date-time field is the date and time of the request in local time and is in the format "[DD/MON/YYYY:HH:MM:SS +ZZZZ]". The method field is the HTTP method used: "GET", "HEAD", "OPTIONS", "POST", or "PUT". "GET" requests are used to get files from the server, both for the web interface and to get configuration and log files. "HEAD" requests are used to get information about a resource prior to a "GET". "OPTIONS" requests are used to upgrade connections to TLS encryption. "POST" requests are used for web interface forms and IPP requests. "PUT" requests are used to upload configuration files. The resource field is the filename of the requested resource. The version field is the HTTP specification version used by the client. For CUPS clients this will always be "HTTP/1.1". The status field contains the HTTP result status of the request, as follows: 200 Successful operation. 201 File created/modified successfully. 304 The requested file has not changed. 400 Bad HTTP request; typically this means that you have a malicious program trying to access your server. 401 Unauthorized, authentication (username + password) is required. 403 Access is forbidden; typically this means that a client tried to access a file or resource they do not have permission to access. 404 The file or resource does not exist. 405 URL access method is not allowed; typically this means you have a web browser using your server as a proxy. 413 Request too large; typically this means that a client tried to print a file larger than the MaxRequestSize allows. 426 Upgrading to TLS-encrypted connection. 500 Server error; typically this happens when the server is unable to open/create a file - consult the error_log file for details. 501 The client requested encryption but encryption support is not enabled/compiled in. 505 HTTP version number not supported; typically this means that you have a malicious program trying to access your server. The bytes field contains the number of bytes in the request. For POST requests the bytes field contains the number of bytes of non-IPP data that is received from the client. The ipp-operation field contains either "-" for non-IPP requests or the IPP operation name for POST requests containing an IPP request. The ipp-status field contains either "-" for non-IPP requests or the IPP status code name for POST requests containing an IPP response. ERROR LOG FILE FORMAT The error_log file lists messages from the scheduler - errors, warnings, etc. The LogLevel directive in the cupsd.conf(5) file controls which messages are logged: level date-time message For example: I [20/May/1999:19:18:28 +0000] [Job 1] Queued on 'DeskJet' by 'mike'. D [20/May/1999:19:18:28 +0000] [Job 1] argv[0]="DeskJet" D [20/May/1999:19:18:28 +0000] [Job 1] argv[1]="1" D [20/May/1999:19:18:28 +0000] [Job 1] argv[2]="mike" D [20/May/1999:19:18:28 +0000] [Job 1] argv[3]="myjob" D [20/May/1999:19:18:28 +0000] [Job 1] argv[4]="1" D [20/May/1999:19:18:28 +0000] [Job 1] argv[5]="media= na_letter_8.5x11in sides=one-sided" D [20/May/1999:19:18:28 +0000] [Job 1] argv[6]="/var/spool/cups/ d000001-001" I [20/May/1999:19:21:02 +0000] [Job 2] Queued on 'DeskJet' by 'mike'. I [20/May/1999:19:22:24 +0000] [Job 2] Canceled by 'mike'. The level field contains the type of message: A Alert message (LogLevel alert) C Critical error message (LogLevel crit) D Debugging message (LogLevel debug) d Detailed debugging message (LogLevel debug2) E Normal error message (LogLevel error) I Informational message (LogLevel info) N Notice message (LogLevel notice) W Warning message (LogLevel warn) X Emergency error message (LogLevel emerg) The date-time field contains the date and time of when the page started printing. The format of this field is identical to the data-time field in the access_log file. The message field contains a free-form textual message. Messages from job filters are prefixed with "[Job NNN]" where "NNN" is the job ID. PAGE LOG FILE FORMAT The page_log file lists each page or group of pages that are sent to a printer. By default, each line contains the following information: printer user job-id date-time page-number num-copies job-billing job-originating-host-name job-name media sides printer user job-id date-time total num-impressions job-billing job-originating-host-name job-name media sides For example the entries for a two page job called "myjob" might look like: DeskJet root 1 [20/May/1999:19:21:05 +0000] 1 1 acme-123 localhost myjob na_letter_8.5x11in one-sided DeskJet root 1 [20/May/1999:19:21:05 +0000] 2 1 acme-123 localhost myjob na_letter_8.5x11in one-sided DeskJet root 1 [20/May/1999:19:21:06 +0000] total 2 acme-123 localhost myjob na_letter_8.5x11in one-sided The PageLogFormat directive in the cupsd.conf(5) file can be used to change this information. The printer field contains the name of the printer that printed the page. If you send a job to a printer class, this field will contain the name of the printer that was assigned the job. The user field contains the name of the user (the IPP requesting-user-name attribute) that submitted this file for printing. The job-id field contains the job number of the page being printed. The date-time field contains the date and time of when the page started printing. The format of this field is identical to the data-time field in the access_log file. The page-number and num-copies fields contain the page number and number of copies being printed of that page. For printers that cannot produce copies on their own, the num-copies field will always be 1. Lines containing the keyword "total" have a num-impressions field instead which provides the total number of impressions (sides) that have been printed on for the job. The job-billing field contains a copy of the job-billing or job-account-id attributes provided with the IPP Create-Job or Print-Job requests or "-" if neither was provided. The job-originating-host-name field contains the hostname or IP address of the client that printed the job. The job-name field contains a copy of the job-name attribute provided with the IPP Create-Job or Print-Job requests or "-" if none was pro- vided. The media field contains a copy of the media or media-col/media-size attribute provided with the IPP Create-Job or Print-Job requests or "-" if none was provided. The sides field contains a copy of the sides attribute provided with the IPP Create-Job or Print-Job requests or "-" if none was provided. SEE ALSO
cupsd(8), cupsd.conf(5), cups-files.conf(5), CUPS Online Help (http://localhost:631/help) COPYRIGHT
Copyright (C) 2007-2017 by Apple Inc. 11 June 2014 CUPS cupsd-logs(5)
All times are GMT -4. The time now is 01:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy