Sponsored Content
Top Forums Shell Programming and Scripting Extract data from a log file and put it in a file Post 303025353 by ctsgnb on Wednesday 31st of October 2018 11:09:33 AM
Old 10-31-2018
Code:
C:\WINDOWS\system32>cat mytst
2018-10-23 12:33:21 AI ERROR -- tpid: SAMPLE_TH  account: 123456789  aiSessionNumber: 660640464  mapName: xxx to yyy
errorDesc: Translation Error:ErrorNumber : 993
ErrorDescriptionSummary: Errors from sources other than XML Status File
ErrorDescriptionDetail : 504



sourceFileName: /apps/EGAPshared/Invoicing/gcs/large_file/XXXXXX001314509_952834960.es2eg.4X
:
--------------------------------------------------------------------------------------------------
2018-10-23 12:33:21 AI ERROR -- tpid: SAMPLE_XX  account: 123654789  aiSessionNumber: 660640457  mapName: xxx to yyy
errorDesc: Translation Error:ErrorNumber : 993
ErrorDescriptionSummary: Errors from sources other than XML Status File
ErrorDescriptionDetail : 504



sourceFileName: /apps/EGAPshared/Invoicing/gcs/large_file/YYYYYY001314509_952834960.es2eg.3X
:
--------------------------------------------------------------------------------------------------
2018-10-23 12:39:15 AI ERROR -- tpid: XXXXX_TH  account: 321456789  aiSessionNumber: 660642348  mapName: xxx to yyy
errorDesc: Translation Error:ErrorNumber : 993
ErrorDescriptionSummary: Errors from sources other than XML Status File
ErrorDescriptionDetail : 504



sourceFileName: /apps/EGAPshared/Invoicing/gcs/large_file/ZZZZZZ001314509_952834960.es2eg.3X

C:\WINDOWS\system32>gawk  -F"[: ]" "/tpid/{print toupper($8) \" = \" $10 OFS $12 \" =\"  $14}/^sourceFileName/{p=toupper(substr($1,1,1));s=tolower(substr($1,2,5)\" \"substr($1,7));sub($1\":\",\" =\",$0); print p s $0}" OFS=" | " mytst
TPID = SAMPLE_TH | account =123456789
Source filename = /apps/EGAPshared/Invoicing/gcs/large_file/XXXXXX001314509_952834960.es2eg.4X
TPID = SAMPLE_XX | account =123654789
Source filename = /apps/EGAPshared/Invoicing/gcs/large_file/YYYYYY001314509_952834960.es2eg.3X
TPID = XXXXX_TH | account =321456789
Source filename = /apps/EGAPshared/Invoicing/gcs/large_file/ZZZZZZ001314509_952834960.es2eg.3X

C:\WINDOWS\system32>




So... with the unix syntax :



Code:
gawk -F"[: ]" '/tpid/{print toupper($8) " = " $10 OFS $12 " =" $14}
/^sourceFileName/{
p=toupper(substr($1,1,1))
s=tolower(substr($1,2,5)" "substr($1,7))
sub($1":"," =",$0)
print p s $0
}' OFS=" | " inputfile


Another approach:
Code:
gawk '{gsub(" ",RS)}1' inputfile | gawk '/(tpid|account|sourceFileName)/{f=$0;getline;print f,$0}'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell-script which extract data from log file

give me a shell-script which extract data from log file on a server by giving date and time as input (for both start time and end time) and it will give the logs generated during the given time as output. (4 Replies)
Discussion started by: abhishek27
4 Replies

2. UNIX for Dummies Questions & Answers

need to extract few lines from a file and put it in another file

Hi all, I have a file which contains comments,dotted lines(-------),actual records etc.I need to fetch only the actual records and put into a new file neglecting/deleting other rows.I have a header record too which contains the column names for the actual records.i need to discard this too.how... (5 Replies)
Discussion started by: ganesh_248
5 Replies

3. Shell Programming and Scripting

Extract data from log file from or after the specific date

Hi , I am having a script which will start a process and appends the process related logs to a log file. The log file writes logs with every line starting with date in the format of: date +"%Y %b %d %H:%M:%S". So, in the script, before I start the process, I am storing the date as DATE=`date +"%Y... (5 Replies)
Discussion started by: chiru_h
5 Replies

4. Shell Programming and Scripting

need a shell script to extract data from a log file.

If I have a log like : Mon Jul 19 05:07:34 2010; TCP; eth3; 52 bytes; from abc to def Mon Jul 19 05:07:35 2010; UDP; eth3; 46 bytes; from aaa to bbb Mon Jul 19 05:07:35 2010; TCP; eth3; 52 bytes; from def to ghi I will need an output like this : Time abc to def... (1 Reply)
Discussion started by: hitha87
1 Replies

5. Shell Programming and Scripting

Data Extract from XML Log File

Please help me out to extract the Data from the XML Log files. So here is the data ERROR|2010-08-26 00:05:52,958|SERIAL_ID=128279996|ST=2010-08-2600:05:52|DEVICE=113.2.21.12:601|TYPE=TransactionLog... (9 Replies)
Discussion started by: raghunsi
9 Replies

6. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

7. Shell Programming and Scripting

Use grep sed or awk to extract string from log file and put into CSV

I'd like to copy strings from a log file and put them into a CSV. The strings could be on different line numbers, depending on size of log. Example Log File: File = foo.bat Date = 11/11/11 User = Foo Bar Size = 1024 ... CSV should look like: "foo.bat","11/11/11","Foo Bar","1024" (7 Replies)
Discussion started by: chipperuga
7 Replies

8. Shell Programming and Scripting

Extract data from log file in specified range of time

I was searching for parsing a log file and found what I need in this link http://stackoverflow.com/questions/7575267/extract-data-from-log-file-in-specified-range-of-time But the most useful answer (posted by @Kent): # this variable you could customize, important is convert to seconds. # e.g... (2 Replies)
Discussion started by: kingk110
2 Replies

9. UNIX for Dummies Questions & Answers

Extract date ranged data from log file

Hi, I am trying to extract lines of data within a log file on a Redhat 5 Linux system. eg I need all the lines with a particular username over the last 3 minutes. the log file may read like this, and I want a way to search all the lines extracting all the relevant lines over the last 3... (2 Replies)
Discussion started by: mantis100
2 Replies

10. Shell Programming and Scripting

Extract data from log file within specified time

So, we have a script, that is supposed to have a couple of functions like showing number of failed connections, recieved bytes per IP-address, and so on. We are supposed to be able to limit the number of results to either 0-24 hours or X days back from the last data in the log file. Everything... (3 Replies)
Discussion started by: Plumpen
3 Replies
MAILQ(1)						      General Commands Manual							  MAILQ(1)

NAME
mailq - print the mail queue SYNOPSIS
mailq [-Ac] [-q...] [-v] DESCRIPTION
Mailq prints a summary of the mail messages queued for future delivery. The first line printed for each message shows the internal identifier used on this host for the message with a possible status character, the size of the message in bytes, the date and time the message was accepted into the queue, and the envelope sender of the message. The second line shows the error message that caused this message to be retained in the queue; it will not be present if the message is being processed for the first time. The status characters are either * to indicate the job is being processed; X to indicate that the load is too high to process the job; and - to indicate that the job is too young to process. The following lines show message recipients, one per line. Mailq is identical to ``sendmail -bp''. The relevant options are as follows: -Ac Show the mail submission queue specified in /etc/mail/submit.cf instead of the MTA queue specified in /etc/mail/sendmail.cf. -qL Show the "lost" items in the mail queue instead of the normal queue items. -qQ Show the quarantined items in the mail queue instead of the normal queue items. -q[!]I substr Limit processed jobs to those containing substr as a substring of the queue id or not when ! is specified. -q[!]Q substr Limit processed jobs to quarantined jobs containing substr as a substring of the quarantine reason or not when ! is specified. -q[!]R substr Limit processed jobs to those containing substr as a substring of one of the recipients or not when ! is specified. -q[!]S substr Limit processed jobs to those containing substr as a substring of the sender or not when ! is specified. -v Print verbose information. This adds the priority of the message and a single character indicator (``+'' or blank) indicating whether a warning message has been sent on the first line of the message. Additionally, extra lines may be intermixed with the recipients indicating the ``controlling user'' information; this shows who will own any programs that are executed on behalf of this message and the name of the alias this command expanded from, if any. Moreover, status messages for each recipient are printed if available. Several sendmail.cf options influence the behavior of the mailq utility: The number of items printed per queue group is restricted by MaxQueueRunSize if that value is set. The status character * is not printed for some values of QueueSortOrder, e.g., filename, random, modification, and none, unless a -q option is used to limit the processed jobs. The mailq utility exits 0 on success, and >0 if an error occurs. SEE ALSO
sendmail(8) HISTORY
The mailq command appeared in 4.0BSD. $Date: 2013-11-22 20:51:55 $ MAILQ(1)
All times are GMT -4. The time now is 05:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy