- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- ed help- join two lines on file based on error log...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2008 12:50 AM
тАО06-19-2008 12:50 AM
ed help- join two lines on file based on error log line number
I have one requirement on file manupulation(joing lines based on error log files's line number).
One of my script upload files on database and sometimes this gives
error on log file. The error is looked like below:
847: Error in load file line 1.
Error in line 2
Near character position 16
Now, checking the error log file, i edit the file using vi manually (for thos case join line 1 and line 2, see below sample file). I want this to be automated (without vi).
Please provide any script(Awk, sed, ed anything is welcome, I think ed can help out. ) which will look into the error log file, and checking the line number (Error in load file line 1, Error may happen in any line), join the next line and said line on the file, say DBLOAD.
Sample of the file (assume file name DBLOAD) is in below: ( I have added Line 1--, Line 2--, Line 3--. Line 4-- above of each line of DBLOAD file to understand the line number.)
Line 1--
"F","1","2008/06/18","09:02:59","MA0002","MAA","IN","MAA","2008/06/18","08:27:1
1","kg","","1,2,3","2008/06/18","","INDOXTMPLT000","D,X,B,N,P,U,F,E","",
Line 2--
"M","MA000218068",
Line 3--
"A","1","1","MA000218068","1490401216","R","RTM","NL","VOM","D ","1\ 1","0.1
","DOCUMENTS","","","ABN AMRO BANK NV","MAILROOM","VAN OLDENBARNEVELTPLAATS 22",
"ROTTERDAM","","3012 AH","","","NL","+31205359000","SYNDICATE BANK","","PAVAN CO
MMERCIAL COMPLEX","FL. 1-2 DABAGARDENS 30-15-147","","530020","","","IN","",
Line 4--
"A","1","2","MA000218068","1503152291","R","BSL","CH","VOM","D ","1\ 1","0.1
2","BUSINESS DOCUMENT","","","GLENCORE INTERNATIONAL AG","ZINC + COPPER",".","BA
ARERMATTSTRASSE 3","","6341","","","CH","O41 709 20 00","STERLITE INDUSTRIAL (IN
DIA) LIMITED",".","MADURAI BYPASS ROAD","SIPCOT INDUSTRIAL COMPLEX","","628002",
"","","IN","+91 22 6643 4599",
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2008 01:29 AM
тАО06-19-2008 01:29 AM
Re: ed help- join two lines on file based on error log line number
awk '
/Error in load file line/ {
# perform concatenation
print "NR ==", substr($NF, 1, length($NF)-1), "{ printf $0; getline }"
}
END { print "{print $0}" } ' errorlog-file > $TMP
cat $TMP # check script to edit DBLOAD
awk -f $TMP DBLOAD > DBLOAD.new
rm -f $TMP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2008 04:36 AM
тАО06-19-2008 04:36 AM
Re: ed help- join two lines on file based on error log line number
I have run the below program as per you like below, however nothing happens.
TMP=/var/tmp/el.$$
awk '/Error in line/ { # perform concat
print "NR==",substr($NF,1,$length($NF)-1),"{ printf $0;getline }"
}
END { print $0 }' errorlog-file > $TMP
cat $TMP
awk -f $TMP DBLOAD >DBLOAD.new
rm -f $TMP
While running i am getting error message as :
syntax error The source line is 1.
The error context is
NR== >>> { <<<
Contents of /var/tmp/el.$$ is NR== {printf $0;getline}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2008 09:06 AM
тАО06-19-2008 09:06 AM
Re: ed help- join two lines on file based on error log line number
I ask myself, if it wouldn't be better to check the file for correctness BEFORE using it.
If there is a fixed number of records needed, this will output all line numbers containing NOT exactly n=36 fields:
awk -F, -v n=36 'NF != n {print NR,NF}' infile
will output (your example):
1 28
2 3
Assuming, your example would show
1 28
2 8
or
1 28
2 3
3 5
i.e. the number of fields of incomplete consequitive lines addup to your field count,
the following would join these lines:
awk -F, -v n=36 '{if(NF+hold > n) { print ("ERROR: overflow in line",NR); hold=0; exit 1}
hold+=NF;hold_str=hold_str""$0
if(hold==n) {print NR,hold_str;hold_str="";hold=0} }
END {if(hold) {print ("ERROR: incomplete file"); exit 1}}' infile
This awk aborts on errors.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2008 09:22 AM
тАО06-19-2008 09:22 AM
Re: ed help- join two lines on file based on error log line number
Here's one way:
# cat joiner
#!/usr/bin/perl
use strict;
use warnings;
my $linenbr = shift;
my $file = shift;
die "Usage $0: linenumber file\n"
unless $file && $linenbr && $linenbr =~ m/^\d+$/;
open( FH, "<", $file ) or die "Can't open '$file': $!\n";
while (
if ( $. == $linenbr ) {
chomp;
$_ .=
redo unless eof(FH);
}
print;
}
1;
...pass the target line-number to which you want to join the successive line along with the name of the file. For example:
# ./joiner 1 log
...would join line-2 to line-1
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2008 10:03 AM
тАО06-19-2008 10:03 AM
Re: ed help- join two lines on file based on error log line number
forgot: to remove the trace of line numbers, change
if(hold==n) {print NR,hold_str;hold_str="";hold=0} }
to
if(hold==n) {print hold_str;hold_str="";hold=0} }
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-19-2008 01:07 PM
тАО06-19-2008 01:07 PM
Re: ed help- join two lines on file based on error log line number
The error context is
NR== >>> { <<<
This means there is something wrong with your description of your error file.
What is the exact format of this error message?
847: Error in load file line 1.
My script expects it to look like that.