[英]How to append the lines using SED or AWK until a particular pattern does not matches?
I want to append the line which does not start with a given pattern
. 我想添加不以given pattern
开头的行。 But i am unable to do that using sed
. 但是我无法使用sed
做到这一点。 Plz help me to solve the problem using either sed
or awk
. 请使用sed
或awk
帮助我解决问题。 For an Example: 例如:
INPUT: INPUT:
18:55:42[pool-1-thread-2] INFO jfileupload.download.http.a - Download completed
18:55:42[HTTPDOWNLOAD] ERROR jfileupload.download.ui.DownloadTransferUI -
java.io.IOException: Failed to show URI:file:/home/rahul/Desktop/
at sun.awt.X11.XDesktopPeer.launch(XDesktopPeer.java:114)
at sun.awt.X11.XDesktopPeer.open(XDesktopPeer.java:77)
at java.awt.Desktop.open(Desktop.java:272)
at jfileupload.download.ui.DownloadTransferUI.a(Unknown Source)
at jfileupload.download.http.HTTPDownloadTransfer.a(Unknown Source)
at jfileupload.download.a.a.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
18:55:43[MultiThreadedHttpConnectionManager cleanup] DEBUG org.apache.commons.httpclient.MultiThreadedHttpConnectionManager - ReferenceQueueThread interrupted
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$ReferenceQueueThread.run(MultiThreadedHttpConnectionManager.java:1122)
Required Output: 要求的输出:
18:55:42[pool-1-thread-2] INFO jfileupload.download.http.a - Download completed
18:55:42[HTTPDOWNLOAD] ERROR jfileupload.download.ui.DownloadTransferUI -java.io.IOException: Failed to show URI:file:/home/rahul/Desktop/, at sun.awt.X11.XDesktopPeer.launch(XDesktopPeer.java:114), at sun.awt.X11.XDesktopPeer.open(XDesktopPeer.java:77), at java.awt.Desktop.open,(Desktop.java:272), at jfileupload.download.ui.DownloadTransferUI.a(Unknown Source), at jfileupload.download.http.HTTPDownloadTransfer.a(Unknown Source), at jfileupload.download.a.a.run(Unknown Source), at java.lang.Thread.run(Thread.java:745)
18:55:43[MultiThreadedHttpConnectionManager cleanup] DEBUG org.apache.commons.httpclient.MultiThreadedHttpConnectionManager - ReferenceQueueThread interrupted,java.lang.InterruptedException, at java.lang.Object.wait(Native Method), at java.lang.ref.ReferenceQueue.remove,(ReferenceQueue.java:135), at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151), at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$ReferenceQueueThread.run(MultiThreadedHttpConnectionManager.java:1122)
In the above input i want to append the next line into current line with ,
until the new line start with such pattern 18:55:42
. 在上面的输入中,我想将下一行添加到当前行中,
直到新行以18:55:42
这样的模式18:55:42
。
Thanks. 谢谢。
not tried it but this should work 没有尝试过,但这应该工作
awk '/[0-9]+:[0-9]+:[0-9]+/{x=$0}{a[x]=a[x]?a[x]", "$0:$0}END{for (i in a)print a[i]}' file
. 。
/[0-9]+:[0-9]+:[0-9]+/ If this pattern is matched
{x=$0} Set x to the value of the line
{a[x]=a[x]?a[x]", "$0:$0} Create associative array with x($0) using ternary
operator to check there is a value in a[x] to
begin with. Adds the current lines value to the
a[x]
END{for (i in a)print a[i]} When all records are processed loop through array
and output values
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.