Rendering that in actual perl syntax is pretty simple, and will be less verbose than what I've shown. Let us know if you have a problem with that step.while ( reading from the input file yields a line of data ) { if ( the line begins with "RS," ) { replace the newline character(s) at the end of the line with a c +omma save this line in a variable called $line_out } elsif ( the line begins with "RAd," ) { replace the final newline character(s) with a comma (just like a +bove) append this line to $line_out } elsif ( the line begins with "RC," ) { print $line_out with the current line appended to it. } }
UPDATE: I added a more specific condition to get into the third block (for printing output), and I added commas to the regex-match conditions for all three blocks, just to be "safe".
Another update: I didn't intend to be obtuse - here's what I meant in actual perl code:
use strict; use warnings; my $line_out; open ( MOV, "<", "test.cxv" ) or die "test.csv: $!\n"; while (<MOV>) { if ( /^RS,/ ) { s/\s+$/,/; $line_out = $_; } elsif ( /^RAd,/ ) { s/\s+$/,/; $line_out .= $_; } elsif ( /^RC,/ ) { print $line_out . $_; } }
In reply to Re^3: duplicating the rows and joining three lines into one using perl script
by graff
in thread duplicating the rows and joining three lines into one using perl script
by rpinnam
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |