?
Solved

combine multiple lines

Posted on 2016-11-04
2
Medium Priority
?
99 Views
Last Modified: 2016-11-04
Hi I have a file and I need to combine the lines

example:

From this

START=so_documentation Upd so_doc_source=M so_module=AGENT_LOG_ROLLOVER so_doc_\
START=type=Module


to this

START=so_documentation Upd so_doc_source=M so_module=AGENT_LOG_ROLLOVER so_doc_type=Module

Not sure the code would be since on multiple lines.

There could be multiple lines as the text wraps at 8 characters.
Its basically un-wraping the lines.

Thanks

Mike
0
Comment
Question by:mikeysmailbox1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
JesterToo earned 2000 total points
ID: 41874870
This may not be the most elegant code (it is the first perl script I've ever written), but it appears to work with data based on the pattern of the limited sample you provided...

use strict;
use warnings;

my $filein    = 'datain.txt';
my $fileout   = 'dataout.txt';

my $newline   = '';
my $firstpart = '';
my $lastchar  = '';
my $firstequal = 0;
my $state      = 0;
my $backslash  = "\\";
my $trash      = '';

open(my $fhin, '<:encoding(UTF-8)', $filein)
  or die "Could not open file '$filein' $!";

open(my $fhout, '>:encoding(UTF-8)', $fileout)
  or die "Could not open file '$fileout' $!";

while (my $row = <$fhin>) {
  chomp $row;
  $firstequal = index $row, '=';
  $firstequal++;
  $lastchar = substr $row, -1;

  $state = 0;
  if (($newline eq '') && ($lastchar ne $backslash)) {
    $state = 1;
     }
  if (($newline eq '') && ($lastchar eq $backslash)) {
     $state = 2;
     }
  if (($newline ne '') && ($lastchar ne $backslash)) {
     $state = 3;
     }
  if (($newline ne '') && ($lastchar eq $backslash)) {
     $state = 4;
     }

  if ($state == 1) {
     print $fhout $row . "\n";
     }

  if ($state == 2) {
     $trash = chop($row);
     $newline = $newline . $row;;
     }

  if ($state == 3) {
     $firstpart = (substr $row, $firstequal);
     print $fhout $newline . $firstpart . "\n";
     $newline = '';
     }

  if ($state == 4) {
     $firstpart = (substr $row, $firstequal);
     $trash = chop($firstpart);
     $newline = $newline . $firstpart;
     }
}

close $fhout;
close $fhin;

Open in new window

1
 
LVL 1

Author Closing Comment

by:mikeysmailbox1
ID: 41875035
The worked great. Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question