INPUT---------------------------------------------------
03,323868096,,015,0,,,045,0,,,072,0,,,074,0,,,040,0,,,050,0,,,043,0,,,055,0,,/^M
88,100,2287432,1,0,400,2287432,52,12, ^M
16,275,2287432,0,0041880118XF,,/ ^M
88,REMARK : STANDING INSTR FROM: 323-126065 ADT FLOAT XFER CREDIT ^M
16,469,207805,0,2348128762TC,,/ ^M
OUTPUT----------------------------------
03,323868096,,015,0,,,045,0,,,072,0,,,074,0,,,040,0,,,050,0,,,043,0,,,055,0,,/^M
88,100,2287432,1,0,400,2287432,52,12,^M
16,275,2287432,0,0041880118XF,,/^M
88,REMARK : STANDING INSTR FROM: 323-126065 ADT FLOAT XFER CREDIT^M
16,469,207805,0,2348128762TC,,/^M
-------------------------------------------------------------------------
I'm trying to get rid of space before ^M.Where ^M is a one character.I want my output file as shown above with new line character...I wanna use SUBstring funct
ion as I used in program below. If someone can help me out with this code..also if anyone has other suggestion please let me know.
#!/usr/bin/perl
open (diff, "<SAPPDAY.00063");
open (out, ">SAPPDAY.00063.new");
while (<diff>) {
if (/(^16|^88)/) {
@words=split(/,/, $_);
$field_cnt=$#words ;
print " Field count = $field_cnt\n" ;
$last_length=length($words[$field_cnt]) ;
$num1 =$last_length-1;
if ( substr($words[$field_cnt], $num1, 1) eq " " ) {
$part1 = substr($words[$field_cnt], 0, -2 );
$part2 = substr($words[$field_cnt], $last_length, 1
+ );
$words[$field_cnt] = $part1 . $part2;
print out "$words[field_cnt]\n";
}
}
}
~
In reply to Substring1
by Anish
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.