Linux - NewbieThis 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.
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.
I'm mining logs in an attempt to create a pipe delimited file. I have the below awk statement, but I can't seem to get the appropriate output onto the correct line:
The end was most likely left over from previous attempts at this bit of functionality. printf gets everything into a single line. I need to have my output as above. Some tables will have migrate dates while others do not. If a table has a migrate date, then I need a new line. If a table does not have a migrate date, I also need a new line to start with the next table name. Thanks for your help and also the link provided. I will continue to research.
I believe I've already converted the first print to a printf. Additionally, that last input line will not always contain /migration process started/. My biggest challenge throughout the logfile is that not all the input will be identical in format. Thanks for your assistance, I will continue to research.
nz_migrate table table1
.....processing table 1 of 1396
.....truncating the target table
.....migration process started at 2015-11-29 07:00:09
.....estimated # of records 2
.....nzload starting ( thread 1 of 1 )
.....unloading data ( thread 1 of 1 )
.....data flowing.....
.....unload results ( thread 1 of 1 ) INSERT 0 2
.....unload finished ( thread 1 of 1 ) elapsed seconds: 3
.....nzload finished ( thread 1 of 1 ) elapsed seconds: 3
.....nzload successful ( thread 1 of 1 )
.....migration process ended at 2015-11-29 07:00:12
.....data flow finished
.....actual # of records unloaded 2
.....
.....migration completed TOTAL seconds: 3
.....
.....cksum process started at 2015-11-29 07:00:12
.....cksum process ended at 2015-11-29 07:00:14
.....confirmed cksum: 0.0 2 table1
.....
.....cksum completed TOTAL seconds: 2
.....
.....launching generate statistics (in the background)
nz_migrate table table2
.....processing table 2 of 1396
.....truncating the target table
.....source table is empty, no data to migrate
.....actual # of records unloaded 0
.....
.....migration completed TOTAL seconds: 0
It's a bit tricky to get the newlines alright, especially in the first and the last section (output line).
The following uses a variable nl that is empty in the first line. At the END a pending newline is printed.
There are innumerable ways to fix this. Testing for a condition that doesn't exist is not a good one.
Simplest probably just to force a newline first in the initial printf. Will give you a null line as first line of output, but in need that can be worked around using something like the nl in post #8.
Better to use regex rather than a fixed number of blanks in the test too ... output formats have been known to change without warning.
But it might be better to work with next statements in the actions - that is, when you are done with the processing of /migrate table/ lines, next; when you are done with the proceesing of /migration process/ lines, next, and then print a newline.
syg00, you are correct. I am not terribly well versed on awk programming. However, I sincerely appreciate everyone's comments on my issue. Grails solution provides what I need however I submitted only two search conditions for my scripts as I thought it would a good jumping off point for the several other strings I need to search for also:
Code:
awk '
> /nz_migrate/{printf (x?"\n":"")$3"|";x=2} \
> /.....migration process started/{print $5" "$6"|";x=1 \
> /.....migration process ended/{print $5" "$6"|";x=0 \
> }' tony.log
awk: cmd. line:3: /.....migration process ended/{print $5" "$6"|";x=0 \
awk: cmd. line:3: ^ syntax error
awk: cmd. line:3: /.....migration process ended/{print $5" "$6"|";x=0 \
awk: cmd. line:3: ^ syntax error
awk: cmd. line:5: }
awk: cmd. line:5: ^ unexpected newline or end of string
I'm researching arrays so I can see how to incorporate grail's suggestions to additional criteria. Thanks to all who replied. I'll get this figured out.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.