I need to remove a section of text on a line that is between two patterns.
This is the line:
Begin : Transaction Id 00004d9e769065ab 04-Oct-2011 04:01:48.69 Username smith
I need the line to read:
Begin : 04-Oct-2011 04:01:48.69 Username smith
I then need to add some text/chars so the line will read as follows:
Begin : Datetime [04-Oct-2011 04:01:48.69], Username [smith]
I think I can get the last line once I get the text removed that I need out of there. I need help getting the ']' at the end though.
Thank you !!!
echo 'Begin : Transaction Id 00004d9e769065ab 04-Oct-2011 04:01:48.69 Username smith' | nawk '{print $1,$2, "Datetime [" $(NF-3) " " $(NF-2) "],", $(NF-1) " [" $NF "]"}' OFS="\t"
thank you, that works for the line but I need to run it through an entire transaction log file and change all of the lines that have 'Begin ' to the format I outlined above.
You didn't post a sample of the entire log file...
This is just a guess...
nawk '/^Begin/ {print $1,$2, "Datetime [" $(NF-3) " " $(NF-2) "],", $(NF-1) " [" $NF "]"}' OFS="\t" myLogFile
Thank you ! Unfortunately the code stripped everything but the "Begin' lines.
This is what I should have posted the very first time - sorry for the confusion.
The log below >>>
Begin : Transaction Id 00004d9e769065ab 04-Oct-2011 04:01:48.69 Username smith
data data data data
End : Transaction Id 00004d9e7690665c 04-Oct-2011 04:01:49.57
data data data data
Insert : Transaction Id 00004d9e7690665a Id (22,0) Table [machines,smith]
data data data data data
Update : Transaction Id 00004d9e777d2d1b Id (312441,0) Table [testsystem,smith]
data data data data
Delete : Transaction Id 00004d9e777ba197 Id (1,0) Table [system,smith]
data data data data
Needs to look like this log >>>>
Begin : Datetime [04-Oct-2011 04:01:48.69], [Username smith]
data data data data
End : Datetime [04-Oct-2011 04:01:49.57]
data data data data
Insert : Table [machines,smith]
data data data data data
Update : Table [testsystem,smith]
data data data data
Delete : Table [system,smith]
data data data data
Thank you !
nawk '/^Begin/ {print $1,$2, "Datetime [" $(NF-3) " " $(NF-2) "],", $(NF-1) " [" $NF "]";next}$1 ~ /Insert|Update|Delete/ {$0=$1 OFS $2 OFS $(NF-1) OFS $NF}1' OFS='\t' myFile
Thank you ! I think that took care of everything but the 'End' line.
nawk '/^Begin/ {print $1,$2, "Datetime [" $(NF-3) " " $(NF-2) "],", $(NF-1) " [" $NF "]";next}$1 ~ /Insert|Update|Delete/ {$0=$1 OFS $2 OFS $(NF-1) OFS $NF}$1~/End/ {$0=$1 OFS $2 OFS "Datetime [" $(NF-1) " " $NF}1' OFS='\t' myFile
THANK YOU !!!
That did the trick !