I am attempting to print some info from a flat text file.
I was able to merge text that had been wrapped but now
need to print only the lines with complete value.
here is an example of what is in the file
Switch name|Up|VCC|||||||||||||||
RTC2||50.1|13|1|376|510|UBR|7|2|65|65|10|384|384|0|3|Off
RTC1||50.2|3|2|23|191/3|UBR|7|2|65|65|10|38|38|40665|3|Off
Switch name|Up|VCC|||||||||||||||
RTC2||50.1|9|1|14|201|UBR|7|2|65|65|10|64|64|320|3|On
RTC1||50.2|3|2|23|435/7|UBR|7|2|65|65|10|38|38|40665|3|Off
Switch name|Up|VCC|||||||||||||||
Switch name complete|Up|VCC|
RTC2||50.1|12|1|411|16|VBR(NRTime)|3|2|65|65|10|128|128|128|1|On
RTC1||50.2|3|2|23|106/9|UBR|7|2|65|65|10|38|38|40665|1|Off
Switch name|Up|VCC|||||||||||||||
Switch name complete|Up|VCC|
RTC2||50.1|12|1|411|16|VBR(NRTime)|3|2|65|65|10|128|128|128|1|On
RTC1||50.2|3|2|23|106/9|UBR|7|2|65|65|10|38|38|40665|1|Off
My problem is I need the Switch name on the single lines
but don't need them on the Switch name complete lines.
here is a copy of the script I use to build this file.
If anyone has any better ideas on how to build the file
or parse out the extra line on the file that was created
I would greatly appreciate it
I have spent two days attempting to parse out the first line
of the duplicate lines with nothing but frustration
#!/usr/bin/perl<br>
<br>
my %current = ();<br>
my @fline = ();<br>
my $original = "";<br>
open (DATA, "/export/home/webadm/scripts/backup_scripts/backup_data/1s
+tnodupe");
while (<DATA>) {
my @line = split(/\|/); # split on |
@current{qw/name var1 var2 var3 var4 var5 var6 var7 var8 var9 var1
+0 var11 var12 var13 var14 var15 var16 var17 var18/} = @line;
#------------------------------
# process first two lines
#-----------
if ($line[0] =~ /^\S/) { # if line = Non-White Space Charac
+ter (equal to first line in 3 line data)
if (keys %current) {
print;
@fline = @line;
$original = $line[0];
}
}
#---------------------------
# process overflow
#---------
elsif ($line[0] =~ /^ (.*)/) {
my $new = $line[0];
@next = split(/ /, $new);
$overflow = $original.$next[1];
print "$overflow\|$fline[1]\|$fline[2]\|\n";
}
#------------------------
# process rtc1 and rtc2
#-----------
else {
print; # print rest of lines
}
}
This file is pretty extensinve, almost 35,000 lines
with the only pattern being one partial switch name
followed by a full switch name
followed by rtc1 and rtc2
Thank you in advance,
Er1k the Rookie
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.