I have log files with following format -
Now the message itself can be multi line message containing new line character.
for e.g.
I would like to sort this file based on time stamp ascending order, i.e., output like this -
Thanks in advance for looking to it and helping out.
I haven't tried your suggestion......
but just for understanding, what it does is -
1. check the pattern 2013 .
2. if the pattern is found, print it as such.
3. If the pattern is not found, prefix each pf those lines with _^_, then sort and replace back.
pls correct if wrong.
so making it generic, i can use a 4 digit year pattern as well, so as not to restrict with 2013, and infact can use my time stamp prefix itself as pattern. right?
another,
does
takes care of newline replacement as well?
I haven't tried your suggestion......
but just for understanding, what it does is -
1. check the pattern 2013 .
2. if the pattern is found, print it as such.
3. If the pattern is not found, prefix each pf those lines with _^_, then sort and replace back.
pls correct if wrong.
so making it generic, i can use a 4 digit year pattern as well, so as not to restrict with 2013, and infact can use my time stamp prefix itself as pattern. right?
another,
does
takes care of newline replacement as well?
Thanks again for your time.
Hi gini32,
Reformatting pamu's script and adding line numbers for discussion purposes:
Note that the line numbers cannot actually appear in your awk script; they are just to make this discussion easier.
The awk program is made up of the commands on lines 2 through 5.
Line 2 selects any line that contains the string 2013 and assumes that it is the 1st line of an entry. (If 2013 could appear anywhere other than at the start of a line, it would be safer to change /2013/ to /^2013/ so the line will be selected only if 2013 appears as the 1st four characters on the line.) The first time you get here, the variable s will be an empty string and the print command will not be executed.
Line 3 then sets s to the current input line.
Line 4 appends every line that does not contain the string2013 to the end of the variable s using the string _^_ (rather than newline) as the output line separator. (If you change /2013/ to /^2013/ on line 2, you need to make the same change on line 4.
Lines 2-4 are then repeated until all lines have been read from the input file.
Line 5 prints the last line from the value accumulated in the variable s.
Line 6 specifies that the input file for the awk script is the file named file3, sorts the output from awk, and then uses sed to change the _^_ line separators that were inserted by awk back into newline characters.
Note that this script assumes that the concatenated lines won't be longer than {LINE_MAX} bytes on your system. If this isn't true the script may fail because awk, sort, and sed are only guaranteed to work if input and output files being processed are text files (which, by definition, have lines no longer than {LINE_MAX} bytes including the terminating newline character. (You can find the value of {LINE_MAX} on your system by running the command:
On systems that conform the POSIX or UNIX Standards, {LINE_MAX} must be at least 2048.
This User Gave Thanks to Don Cragun For This Post:
Hi,
Can anyone help me for merge the following multi-line log which beginning with a " and line ending with ": into one line.
*****Original Log*****
087;2008-12-06;084403;"mc;;SYHLR6AP1D\LNZW;AD-703;1;12475;SYHLR6AP1B;1.1.1.1;0000000062;HGPDI:MSISDN=12345678,APNID=1,EQOSID=365;... (3 Replies)
I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line
Source file
07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
I have a file with data records separated by multiple equals signs, as below.
==========
RECORD 1
==========
RECORD 2
DATA LINE
==========
RECORD 3
==========
RECORD 4
DATA LINE
==========
RECORD 5
DATA LINE
==========
I need to filter out all data from this file where the... (2 Replies)
Hi,
My Oracle query is returing below o/p
----------------------------------------------------------
Ins trnas value
a lkp1 x
a lkp1 y
b lkp1 a
b lkp2 x
b lkp2 y ... (7 Replies)
I want to sort like below
Suppose few lines in a file is like this
systemid:ABC messagedestination:batchxpr replytoqname: myca
systemid:BCD messagedestination:realtime replytoqname: myca
systemid:ABC messagedestination:realtime replytoqname: eac
systemid: BCD messagedestination:mqonline... (1 Reply)
Good morning. I have a piece of code that is currently taking multiple files and using the CAT.exe command to combine into one file that is then sorted in reverse order based on the 3rd field of the file, then displayed on screen. I am trying to change this so that the files are being combined into... (4 Replies)
Hi, all.
I need a shell script which gathers data from a remote XML file and then displays it according to my needs.. I need this for my job due to the fact that I need to keep track price changes of euro, usd, gold, etc.
The XML file I am talking about is located at this page: cnnturk dot... (4 Replies)
Hi all
I have data in following format:
CSCH74,2007,1,09103,15
CSCH74,2007,10,09103,0
CSCH74,2007,11,09103,0
CSCH74,2007,12,09103,0
CSCH74,2007,2,09103,15
CSCH74,2007,3,09103,194
CSCH74,2007,4,09103,115
CSCH74,2007,5,09103,66
CSCH74,2007,6,09103,0
CSCH74,2007,7,09103,0... (2 Replies)