0

Below is my data , i am not able to remove newline character with sed or awk command . When I use tr command, all records merge as single record and sed and awk not able to help.

Can you please let me know the command if you any one faced this type of data.

"2016-03-05 00:48:11|0|I|NOT SET   ||||||||||||||||2014-01-13-12.27.15.234361|2014-01-14| |0|"
"PLS RPL  2 TR-NS FATAL ERROR  |2 TR-NS FATAL ERROR                                 |TRBLRPRT|BDTRRPL|BWRINERR|0|||        ||                                                                      "
"2016-03-05 00:48:11|0|I|NOT SET   ||||||||||||||||2014-03-30-16.08.41.215789|2014-04-01| |0|"
"PLS RPLC BAD TR                 |PLS RPLC BAD TR                                       |TRBLRPRT|BDTRRPL|        |0|||        ||                                                                      "
"2016-03-05 00:48:11|0|I|NOT SET   ||||||||||||||||2014-04-08-13.32.59.536559|2014-04-09| |0|FATAL ERROR 3 PLEASE REFER"
"TO ETE|                                                       |TRBLRPRT|BDTRRPL|        |0|||        ||                                                                      "
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Santhosh Kancherla
  • 173
  • 1
  • 1
  • 9
  • This is the my record start postition 2016-03-05 00:48:11 – Santhosh Kancherla Mar 07 '16 at 04:20
  • What should be the record separator if it isn't newline? If you remove newlines, then all lines will be a single line. That's not a surprise. You can't remove newlines and expect all records to be separated by newlines. – alvits Mar 07 '16 at 22:03

1 Answers1

0

Your question isn't very clear, but it looks like your data is split across two lines assuming every line is supposed to begin with a timestamp. This awk command will join the two lines together:

awk 'NR % 2 == 1 { prev = $0; } NR % 2 == 0 { print prev $0; }'

Actually this answer has even more concise ways of doing it with awk or sed.

Community
  • 1
  • 1
Kurt Stutsman
  • 3,994
  • 17
  • 23
  • Not every record is spliting only few records ae spliting into two records , – Santhosh Kancherla Mar 08 '16 at 02:26
  • Well you need to tell us how you're identifying when they're split if you want to unsplit them. – Kurt Stutsman Mar 08 '16 at 02:27
  • actually my data is having lot of reacords like above but after applying below two commads for most of the records newline and controm M characters are removed but still few of the not converting as single record cat $f | tr -d '^M\r'> $f.temp awk 'NR>1 && !/^ /{printf "\n";} {printf "%s",$0} END{print ""}' $f.temp>$f.temp2 these are the commands i am applying on my input data – Santhosh Kancherla Mar 08 '16 at 02:31
  • they are spiling with Newline characters – Santhosh Kancherla Mar 08 '16 at 02:46