Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

G'day bhargavkanakiya,

You say you're OK with the file handling. Here's my solution for the data handling.

  1. Read a line and put it in a buffer.
  2. If line ends with "SIL", go back to 1 (i.e. read another line).
  3. Output all lines in the buffer.
  4. Clear the buffer.
  5. Go back to 1 (i.e. read another line).
  6. When all lines read, output the first line in the buffer.

Here it is on the commandline:

$ perl -Mstrict -Mwarnings -E '
    my @buffer;
    my @input = <>;
    say "========\n Output\n========";
    for (@input) {
        push @buffer, $_;
        next if /SIL\s*$/m;
        print shift @buffer while @buffer;
    }
    print $buffer[0] if @buffer;
'
0.642375 125 SIL 
1.0705 125 ઔર્ 
1.3651875 125 આત્ 
1.519875 125 મ
7.2140627 125 સે 
7.478125 125 હટ્ 
7.622625 125 જા 
7.956125 125 ઓ 
8.192375 125 SIL 
8.252 125 SIL 
8.464 125 SIL 
8.706 125 SIL
========
 Output
========
0.642375 125 SIL 
1.0705 125 ઔર્ 
1.3651875 125 આત્ 
1.519875 125 મ
7.2140627 125 સે 
7.478125 125 હટ્ 
7.622625 125 જા 
7.956125 125 ઓ 
8.192375 125 SIL 

I found some lines had additional whitespace at the end: this may be valid data; a result of your cut-n-paste operation; related to all those special characters; or, something else. Anyway, I used the /SIL\s*$/m regexp to get around this — you may want to modify that for your real-world application.

-- Ken


In reply to Re: removing lines that are in the end of a file by kcott
in thread removing lines that are in the end of a file by bhargavkanakiya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-24 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found