var googletag = googletag || {}; googletag.cmd = googletag.cmd || []; (function() { var gads = document.createElement('script'); gads.async = true; gads.type = 'text/javascript'; var useSSL = 'https:' == document.location.protocol; gads.src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js'; var node = document.getElementsByTagName('script')[0]; node.parentNode.insertBefore(gads, node); })();

  Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Merge multiple lines into a single line

Shell Programming and Scripting


Tags
awk, sed, solved

Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 07-04-2017   -   Original Discussion by dwdnet
dwdnet dwdnet is offline
Registered User
 
Join Date: Jul 2017
Last Activity: 21 July 2017, 10:51 AM EDT
Posts: 12
Thanks: 17
Thanked 0 Times in 0 Posts
Thanks Don. I used the command line below. Right behind each semi-colon is a \r following by what looks like a space.


Code:
awk 'sub (/;$/, "")+1 && $1=$1' RS= infile
0000000 357 273 277 164 151 155 145 163 164 141 155 160 075 062 060 061
        357 273 277   t   i   m   e   s   t   a   m   p   =   2   0   1
0000020 067 055 060 066 055 062 070 055 060 061 056 060 061 056 063 065
          7   -   0   6   -   2   8   -   0   1   .   0   1   .   3   5
0000040 056 060 070 060 065 067 066 073 015 040 145 166 145 156 164 040
          .   0   8   0   5   7   6   ;  \r       e   v   e   n   t    
0000060 163 164 141 164 165 163 075 060 073 015 040 165 163 145 162 151
          s   t   a   t   u   s   =   0   ;  \r       u   s   e   r   i
0000100 144 075 165 163 145 162 061 073 015 040 141 165 164 150 151 144
          d   =   u   s   e   r   1   ;  \r       a   u   t   h   i   d
0000120 075 165 163 145 162 061 073 015 040 141 160 160 154 151 143 141
          =   u   s   e   r   1   ;  \r       a   p   p   l   i   c   a
0000140 164 151 157 156 040 151 144 075 061 060 056 061 060 056 061 060
          t   i   o   n       i   d   =   1   0   .   1   0   .   1   0
0000160 056 061 060 056 061 061 061 061 061 056 061 062 063 064 065 066
          .   1   0   .   1   1   1   1   1   .   1   2   3   4   5   6
0000200 067 070 071 060 061 073 015 040 141 160 160 154 151 143 141 164
          7   8   9   0   1   ;  \r       a   p   p   l   i   c   a   t
0000220 151 157 156 040 156 141 155 145 075 107 125 111 073 015 040 015
          i   o   n       n   a   m   e   =   G   U   I   ;  \r      \r
0000240 040 164 151 155 145 163 164 141 155 160 075 062 060 061 067 055
              t   i   m   e   s   t   a   m   p   =   2   0   1   7   -
0000260 060 066 055 062 070 055 060 061 056 060 061 056 063 066 056 060
          0   6   -   2   8   -   0   1   .   0   1   .   3   6   .   0
0000300 071 066 064 070 066 073 015 040 145 166 145 156 164 040 163 164
          9   6   4   8   6   ;  \r       e   v   e   n   t       s   t
0000320 141 164 165 163 075 060 073 015 040 165 163 145 162 151 144 075
          a   t   u   s   =   0   ;  \r       u   s   e   r   i   d   =
0000340 165 163 145 162 061 073 015 040 141 165 164 150 151 144 075 165
          u   s   e   r   1   ;  \r       a   u   t   h   i   d   =   u
0000360 163 145 162 061 073 015 040 141 160 160 154 151 143 141 164 151
          s   e   r   1   ;  \r       a   p   p   l   i   c   a   t   i
0000400 157 156 040 151 144 075 061 060 056 061 060 056 061 060 056 061
          o   n       i   d   =   1   0   .   1   0   .   1   0   .   1
0000420 060 056 061 061 061 061 061 056 061 062 063 064 065 066 067 070
          0   .   1   1   1   1   1   .   1   2   3   4   5   6   7   8
0000440 071 060 061 073 015 040 141 160 160 154 151 143 141 164 151 157
          9   0   1   ;  \r       a   p   p   l   i   c   a   t   i   o
0000460 156 040 156 141 155 145 075 107 125 111 073 015 040 163 164 141
          n       n   a   m   e   =   G   U   I   ;  \r       s   t   a
0000500 164 145 155 145 156 164 040 164 145 170 164 075 123 105 114 105
          t   e   m   e   n   t       t   e   x   t   =   S   E   L   E
0000520 103 124 040 164 141 142 154 145 056 146 151 145 154 144 054 040
          C   T       t   a   b   l   e   .   f   i   e   l   d   ,    
0000540 164 141 142 154 145 056 146 151 145 154 144 054 040 164 141 142
          t   a   b   l   e   .   f   i   e   l   d   ,       t   a   b
0000560 154 145 056 146 151 145 154 144 040 146 162 157 155 040 144 141
          l   e   .   f   i   e   l   d       f   r   o   m       d   a
0000600 164 141 142 141 163 145 040 167 150 145 162 145 040 164 141 142
          t   a   b   a   s   e       w   h   e   r   e       t   a   b
0000620 154 145 056 146 151 145 154 144 040 075 040 166 141 154 165 145
          l   e   .   f   i   e   l   d       =       v   a   l   u   e
0000640 015 040 015 012
         \r      \r  \n
0000644

Sponsored Links
    #9  
Old Unix and Linux 07-04-2017   -   Original Discussion by dwdnet
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 November 2017, 6:42 AM EST
Location: Aachen, Germany
Posts: 11,616
Thanks: 320
Thanked 3,615 Times in 3,320 Posts
Try

Code:
awk 'gsub (";$|\r", "")+1 && $1=$1' RS= file

The Following User Says Thank You to RudiC For This Useful Post:
dwdnet (07-05-2017)
Sponsored Links
    #10  
Old Unix and Linux 07-04-2017   -   Original Discussion by dwdnet
dwdnet dwdnet is offline
Registered User
 
Join Date: Jul 2017
Last Activity: 21 July 2017, 10:51 AM EDT
Posts: 12
Thanks: 17
Thanked 0 Times in 0 Posts
Thanks RudiC. We are getting closer thanks to you all. The last command put everything on one line. The events should all begin with the timestamp field. So by using the example I provided there should be 2 output lines.
    #11  
Old Unix and Linux 07-04-2017   -   Original Discussion by dwdnet
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 November 2017, 6:42 AM EST
Location: Aachen, Germany
Posts: 11,616
Thanks: 320
Thanked 3,615 Times in 3,320 Posts
You seem not to have any <line feed> chars in your file except in the very end. So mayhap the condition you quoted in post#1 - empty line between records - can't be met with non- *nix files. Is that a MAC file?
The Following User Says Thank You to RudiC For This Useful Post:
dwdnet (07-05-2017)
Sponsored Links
    #12  
Old Unix and Linux 07-04-2017   -   Original Discussion by dwdnet
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 18 November 2017, 3:01 AM EST
Location: San Jose, CA, USA
Posts: 10,651
Thanks: 571
Thanked 3,728 Times in 3,182 Posts
Quote:
Originally Posted by RudiC View Post
You seem not to have any <line feed> chars in your file except in the very end. So mayhap the condition you quoted in post#1 - empty line between records - can't be met with non- *nix files. Is that a MAC file?
We haven't seen enough information to determine whether or not there are <newline> (or <linefeed>) characters in the input file. Using RS= in awk to set the record separator to sequences of blank lines will not treat a line containing a <carriage-return> as a blank line. So, awk won't find any record separators in a DOS input file. (And, if you remove the <carriage-return> characters in the code that will happen AFTER the record separator search has already occurred.)

I would start by trying:

Code:
awk '
function p() {
	if(d) {
		sub(/;$/, "", o)
		print o
		o = ""
		d = 0
	}
}
{	sub(/\r/, "")
}
!NF {	p()
	next
}
{	$1 = $1
	o = o (o == "" ? "" : " ") $0
	d = 1
}
END {	p()
}' file

If that doesn't work, please show us the output from:

Code:
od -bc file

where file is the name of your input file.
The Following User Says Thank You to Don Cragun For This Useful Post:
dwdnet (07-05-2017)
Sponsored Links
    #13  
Old Unix and Linux 07-05-2017   -   Original Discussion by dwdnet
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 November 2017, 6:42 AM EST
Location: Aachen, Germany
Posts: 11,616
Thanks: 320
Thanked 3,615 Times in 3,320 Posts
Hmmm - in the od output in post#8, I find many \r but just one \n. So my question... I only now see the three introductory bytes 357 273 277 - need to double check their meaning...
The Following User Says Thank You to RudiC For This Useful Post:
dwdnet (07-05-2017)
Sponsored Links
    #14  
Old Unix and Linux 07-05-2017   -   Original Discussion by dwdnet
MadeInGermany MadeInGermany is online now Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 18 November 2017, 3:33 AM EST
Location: Simplicity
Posts: 3,822
Thanks: 318
Thanked 1,281 Times in 1,159 Posts
I think the od dump is from your first awk's output that was all on one line.
As Don said, the RS= will not see a \n\r\n but in GNU awk you can set RS="\n\r?\n" or even RS="\n[[:space:]]*\n" to allow any whitespace including \r and further \n.
The Following User Says Thank You to MadeInGermany For This Useful Post:
dwdnet (07-05-2017)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help combining txt files w/ multiple lines into csv single cell - also need data merge jetsetter UNIX for Dummies Questions & Answers 2 02-04-2013 10:12 AM
Merge a group of lines into single line prasanth_babu UNIX for Advanced & Expert Users 8 10-18-2010 02:01 PM
merge lines into single line based on symbol \t repinementer Shell Programming and Scripting 5 07-15-2009 10:16 AM
Help on Merge multi-lines into one single line happyday Shell Programming and Scripting 5 05-25-2009 08:30 AM
Merge multi-lines into one single line happyday Shell Programming and Scripting 4 05-09-2009 02:00 PM



All times are GMT -4. The time now is 04:33 AM.