From Nagios I downloaded its html file by using wget command and then I converted that htmlfile to Textfile by using following code:
JavaScript
x
html2text -width 180 file.html >a.txt
then I cut the first 10 lines becoz I dont want that text and I got below textfile output
JavaScript
awk 'NR > 10 { print }'a.txt > b.txt
I have to merge two rows into single row not for all lines only for particular output from b.txt file. Note: the text file contains N number of lines
Here the b.txt File Output:
JavaScript
DISK OK - free space: CRITICAL
01-08-2018 07:05:05 Service Required Critical CPU:loadaverage 6.0%
01-08-2018 07:10:25 Service Alert Critical memoryUsage
DISK OK - free space:
02-08-2018 01:05:2018 Service Alert Warning memoryUsage
CRITICAl:outstanding alert attention
02-08-2018 02:05:2018 Service Alert Critical required
Expected output:
JavaScript
01-08-2018 07:05:05 DISK OK - free space:Service Required Critical CRITICALservice requiredCPU:loadaverage 6.0%
01-08-2018 07:10:25 Service Alert Critical memoryUsage
02-08-201801:05:2018 DISK OK - free space:Service Alert Warning memoryUsage
02-08-2018 02:05:2018 Service Alert Critical CRITICAL:outstanding alert attention required
Thanks in advance
Advertisement
Answer
You can use awk to merge lines together:
JavaScript
awk '
/^ +/{ # For lines starting with spaces,
gsub(/^ +/," "); # Replace these multiple spaces with only one
a=a $0; # Store the line into the variable a
next # Continue with the next line
}
{ # For lines not starting with spaces
$3=$3 a; # Append the variable a to the third element
a="" # Clear variable a
}
1 # Print the current line
' b.txt