[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

combine multiple lines

Posted on 2016-11-04
2
Medium Priority
?
111 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

650 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