I have questions about the final sequence but I will let those go in favor of addressing the Perl elements first.
Something like this should help get you started, but it does not produce output in the same order you requested:
#!/usr/bin/perl -w use strict; # Loop through input filenames listed on command line foreach my $inpfnm (@ARGV) { # Try to open the file for read (input) if (!open INPFIL, "<$inpfnm") { print "ERROR: Cannot open input file '$inpfnm'\n"; } else { # Derive the output filename my $outfnm = $inpfnm . '-out.dat'; # Try to open the file for write (output) if (!open OUTFIL, ">$outfnm") { print "ERROR: Cannot open output file '$outfnm'\n"; } else { # Loop through lines from the input file while (my $inpbuf = <INPFIL>) { # Remove the newline at the end of the line chomp $inpbuf; # Split input by vertical bar (pipe) character my @inpelt = split /\|/, $inpbuf; # Go through each element from the split foreach my $inpelt (@inpelt) { if ($inpelt !~ /^\s*$/) { # Line is not blank. Proceed. # Prepare output buffer. my $outbuf = $inpelt; # Trim leading and trailing whitespace $outbuf =~ s/^\s+//; $outbuf =~ s/\s+$//; # Write output print OUTFIL "$outbuf\n"; } } } # Cleanup close OUTFIL; } # Cleanup close INPFIL; } } exit; __END__
It gets a little more complicated to process them in the order you requested, but not too much.
Let us know if you need the order you specified or if this sequence is sufficient to your needs.
In reply to Re: concatenating strings
by marinersk
in thread concatenating strings
by alferic
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |