Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
10-19-2016, 01:47 PM
|
#16
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,518
|
Quote:
Originally Posted by dfco
awk -F"~" '{print $1}' testfile.log
|
-F sets the Field Separator. So -F "~" is also the same as starting with a clause 'BEGIN { FS="~" }'
However, given the data you showed above, changing the Field Separator is probably not important.
Do the numbers you want always appear in the same position in each line?
|
|
1 members found this post helpful.
|
10-19-2016, 02:53 PM
|
#17
|
LQ Newbie
Registered: Oct 2016
Posts: 17
Original Poster
Rep:
|
Thanks for your recommendations.
With the following input :
APP_9874 Target: BKG (Instance Name: [BKG])
APP_9889 Inserted rows - Requested: 1218 Applied: 1218 Rejected: 1 Affected: 1218
I tried the script:
awk 'BEGIN{ OFS=";"}
$2 == "Target:" {TARGET_TABLE_NAME = $3}
$2 == "Inserted" {INSERTED_AFFECTED_ROWS = $12;
INSERTED_REJECTED_ROWS = $10}
{print TARGET_TABLE_NAME,INSERTED_AFFECTED_ROWS,INSERTED_REJECTED_ROWS;
TARGET_TABLE_NAME = "";
INSERTED_AFFECTED_ROWS = 0;
INSERTED_REJECTED_ROWS = 0;}' testfile.log
The result is:
BKG;;
;1218;1
The result is expected but my first question is : can I have the result in only one line:
BKG;1218;1
Thanks mates.
|
|
|
10-19-2016, 02:53 PM
|
#18
|
LQ Veteran
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Rep:
|
Quote:
Originally Posted by dfco
The log is a csv file and is generated by an application which insert/update/delete records into a table.
|
Is there some secret to the name of this program?
|
|
|
10-19-2016, 02:56 PM
|
#19
|
LQ Newbie
Registered: Oct 2016
Posts: 17
Original Poster
Rep:
|
Yes the numbers always appear in the same position/order in each line.
|
|
|
10-19-2016, 03:19 PM
|
#20
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,175
|
Quote:
Originally Posted by dfco
Maybe I need to write I am a beginner and complex Linux scripting is something new. The log is a csv file and is generated by an application which insert/update/delete records into a table.
|
And AGAIN, you are not telling us anything...saying "an application" tells us nothing, nor does it clarify anything to say "insert/update/delete records into a table". WHAT table? Where? How does the 'it' know what to update/insert/delete???? You are telling us nothing.
Quote:
I tried to make simplify my need with the last example I gave :
|
Telling us what you NEED over and over again, and ignoring questions that are asked, is pointless. We KNOW WHAT YOU WANT/NEED, but you are not answering questions.
|
|
|
10-19-2016, 03:29 PM
|
#21
|
LQ Newbie
Registered: Oct 2016
Posts: 17
Original Poster
Rep:
|
@TB0ne. Are you serious ? Your questions do not make sense.
|
|
|
10-19-2016, 03:59 PM
|
#22
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,018
|
So it turns out none of us have mentioned yet, but please use [code][/code] tags around your code or data (maintains format and takes up less room
On to your problem, now that we have more information. First of all, your dba or oracle dev could easily extract this information directly from the database.
As to the issue of gleaning the data from the log file, your first issue would be on how to identify which date you wish to look for which I will leave to you
Here is a possible solution ... crude but seems to work:
Code:
#!/usr/bin/awk -f
/SOURCE/{ date = gensub(/^.*E /,"","1") }
/Target/{ tg = $3 }
/Inserted/{
ins[date][tg]["app"] = $8
ins[date][tg]["rej"] = $10
ins[date][tg]["aff"] = $12
}
/Updated/{
upd[date][tg]["app"] = $8
upd[date][tg]["rej"] = $10
upd[date][tg]["aff"] = $12
}
/Deleted/{
del[date][tg]["app"] = $8
del[date][tg]["rej"] = $10
del[date][tg]["aff"] = $12
}
END{
for(d in ins){
print "Results for source date :-",d
for(t in ins[d])
printf("%s,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",t,
ins[d][t]["app"],ins[d][t]["aff"],ins[d][t]["rej"],
upd[d][t]["app"],upd[d][t]["aff"],upd[d][t]["rej"],
del[d][t]["app"],del[d][t]["aff"],del[d][t]["rej"] )
}
}
Last edited by grail; 10-19-2016 at 04:00 PM.
|
|
|
10-19-2016, 04:15 PM
|
#23
|
LQ Newbie
Registered: Oct 2016
Posts: 17
Original Poster
Rep:
|
Thanks a lot Grail. I will try.
This particular info are not stored in the database but only in the log files. Only option is to parse the files. It is unfortunate because it would have been easier with SQL queries.
|
|
|
10-19-2016, 04:29 PM
|
#24
|
LQ 5k Club
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,448
|
This was my more pedestrian solution with a script called using the -f option to awk.
Code:
function initialise() {
TARGET_TABLE_NAME = "";
INSERTED_APPLIED_ROWS = 0;
INSERTED_AFFECTED_ROWS = 0;
INSERTED_REJECTED_ROWS = 0;
UPDATED_APPLIED_ROWS = 0;
UPDATED_AFFECTED_ROWS = 0;
UPDATED_REJECTED_ROWS = 0;
DELETED_APPLIED_ROWS = 0;
DELETED_AFFECTED_ROWS = 0;
DELETED_REJECTED_ROWS = 0 }
BEGIN { initialise(); OFS="," }
$2 == "Target:" { TARGET_TABLE_NAME = $3 }
$2 == "Inserted" { INSERTED_APPLIED_ROWS = $8;
INSERTED_AFFECTED_ROWS = $12;
INSERTED_REJECTED_ROWS = $10 }
$2 == "Updated" { UPDATED_APPLIED_ROWS = $8;
UPDATED_AFFECTED_ROWS = $12;
UPDATED_REJECTED_ROWS = $10 }
$2 == "Deleted" { DELETED_APPLIED_ROWS = $8;
DELETED_AFFECTED_ROWS = $12;
DELETED_REJECTED_ROWS = $10 }
/^$/ { print TARGET_TABLE_NAME,
INSERTED_APPLIED_ROWS,INSERTED_AFFECTED_ROWS,INSERTED_REJECTED_ROWS,
UPDATED_APPLIED_ROWS,UPDATED_AFFECTED_ROWS,UPDATED_REJECTED_ROWS,
DELETED_APPLIED_ROWS,DELETED_AFFECTED_ROWS,DELETED_REJECTED_ROWS;
initialise() }
|
|
2 members found this post helpful.
|
10-19-2016, 04:52 PM
|
#25
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,018
|
Actually, if you switch auditing on this is exactly the sort of information that is available.
|
|
|
10-19-2016, 04:54 PM
|
#26
|
LQ Newbie
Registered: Oct 2016
Posts: 17
Original Poster
Rep:
|
@Grail : What do you mean ?
|
|
|
10-19-2016, 05:50 PM
|
#28
|
LQ Newbie
Registered: Oct 2016
Posts: 17
Original Poster
Rep:
|
You mean DB audit. Maybe for the DML (insert, update, delete, ...) operations but not sure for the rejected records. Not sure my DBA will accept to add more monitor stuffs in DB prod. I am aware of those options and came to the forum because best option is too parse the log files.
|
|
|
10-20-2016, 08:17 AM
|
#29
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,175
|
Quote:
Originally Posted by dfco
@TB0ne. Are you serious ? Your questions do not make sense.
|
What is unclear???? We have been asking you SEVERAL TIMES to tell us where this data is coming from. All you've told us is "an application". What about that don't you understand?
Habitual asked you, I asked you earlier, and Turbocapitalist also asked you questions you didn't answer. It took you to post #15 to actually tell us "oracle data integrator", but you STILL don't say what "the application" is that's going to USE this data, how. Is that so hard?
|
|
|
10-20-2016, 10:59 AM
|
#30
|
LQ Newbie
Registered: Oct 2016
Posts: 17
Original Poster
Rep:
|
Thanks Grail and Allend.
I tried :
Code:
awk '
function initialise() {
TARGET_TABLE_NAME = "";
INSERTED_AFFECTED_ROWS = 0;
INSERTED_REJECTED_ROWS = 0;
UPDATED_AFFECTED_ROWS = 0;
UPDATED_REJECTED_ROWS = 0;
DELETED_AFFECTED_ROWS = 0;
DELETED_REJECTED_ROWS = 0 }
BEGIN{ initialise(); OFS=";"}
$2 == "Target:" {TARGET_TABLE_NAME = $3}
$2 == "Inserted" {INSERTED_AFFECTED_ROWS = $12;
INSERTED_REJECTED_ROWS = $10}
$2 == "Updated" {UPDATED_AFFECTED_ROWS = $12;
UPDATED_REJECTED_ROWS = $10}
$2 == "Deleted" {DELETED_AFFECTED_ROWS = $12;
DELETED_REJECTED_ROWS = $10}
{ print TARGET_TABLE_NAME,INSERTED_AFFECTED_ROWS,INSERTED_REJECTED_ROWS,UPDATED_AFFECTED_ROWS,UPDATED_REJECTED_ROWS,DELETED_AFFECTED_ROWS,DELETED_REJECTED_ROWS;
initialise() }
' testfile.log
And the result is :
Code:
BKG;0;0;0;0;0;0
;1218;1;0;0;0;0
;0;0;1218;1;0;0
;0;0;0;0;1218;1
Is it possible to have only one line :
Code:
BKG;1218;1;1218;1;1218;1
Thanks a lot.
|
|
|
All times are GMT -5. The time now is 09:46 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|