Results 1 to 3 of 3
Hi all. Hoping someone can help me get down the last mile with some log file manipulation.
Here's the scenario. When confronted with the pattern below in a log file, ...
- 03-30-2007 #1Just Joined!
- Join Date
- Mar 2007
- Posts
- 1
File manipulation assitance
Hi all. Hoping someone can help me get down the last mile with some log file manipulation.
Here's the scenario. When confronted with the pattern below in a log file, I am able to successfully create single lines for each entry.
MyServer Fri Jan 26 23:01:27 2007
INET/inet_error: read errno = 104
MyServer Fri Jan 26 23:01:27 2007
INET/inet_error: read errno = 104
MyServer Fri Jan 26 23:01:27 2007
INET/inet_error: read errno = 104
MyServer Fri Jan 26 23:01:27 2007
INET/inet_error: read errno = 104
MyServer Fri Jan 26 23:01:27 2007
INET/inet_error: read errno = 104
To create the single lines, I use paste -s -d '\t\t\n' < input > output, leaving me with the format below which is perfect for pulling into a database and working with from there.
MyServer Fri Jan 26 23:01:38 2007 INET/inet_error: read errno = 104
MyServer Fri Jan 26 23:01:38 2007 INET/inet_error: read errno = 104
MyServer Fri Jan 26 23:01:38 2007 INET/inet_error: read errno = 104
MyServer Fri Jan 26 23:01:38 2007 INET/inet_error: read errno = 104
MyServer Fri Jan 26 23:01:38 2007 INET/inet_error: read errno = 104
My problem is whenever confronted with an entry in the error log that is more than two lines, my paste command falls down. See the example below.
MyServer Fri Jan 26 23:01:27 2007
INET/inet_error: read errno = 104
error processing 3455980x
What I am trying to achieve is something like the above, combining all of the text associated with a single entry into the error log into one continuous line.
MyServer Fri Jan 26 23:01:38 2007 INET/inet_error: read errno = 104 error processing 3455980x
Apologies for the lengthy post, any help would be greatly appreciated.
- 03-31-2007 #2Linux Enthusiast
- Join Date
- Jan 2005
- Posts
- 575
If entries are separated by empty lines then the way to do it is
Code:gawk '{ if ($0 ~ /^$/) {print line ; line = ""} else {line = (line == "" ? $0 : line " " $0)} } END {print line}' log_file
- 03-31-2007 #3Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try this:
RegardsCode:#!/bin/sh while read line do if [ "$line" != "" ]; then if [ ${line:0:8} == "MyServer" -a "$str" != "" ] ; then echo $str str="" fi str=`echo $str $line` fi done < log_file echo $str


Reply With Quote