Results 1 to 12 of 12

Thread: Help with .txt line deletion Script

  1. #1
    Join Date
    Jun 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Question Help with .txt line deletion Script

    So here's the problem: My Friends program shoots out data into a text file every 10 seconds, but I only need the data every minute which leaves me with 6 times the data I need. The data is set up in the .txt file to be converted into a CSV(comma seperated values) by MSExcel.
    A .txt file in CSV format looks like this:
    Code:
    1,1
    2,2
    3,3
    4,4
    5,5
    6,6
    Excel will take that information and convert

    Code:
    2,2
    into

    Code:
      _|A|B|
    |1|2|2|
    So Before I convert the file I need to figure out how to delete lines 1-5 but not 6

    Ex:
    Code:
    1,1 = Delete
    2,2 = Delete
    3,3 = Delete
    4,4 = Delete
    5,5 = Delete
    6,6
    HOWEVER, they are not conveniently numbered like that, or so with little text
    Expect something like:
    Code:
    91.8,30.4
    961,178
    1832,1039
    123,18.137
    1241,18247.2
    1264,1284
    123,172.1284
    1274,1263.1298
    1283
    12812, 12364
    980, 1248901
    98435,127.2
    etc... probably at least 200+ lines
    In that example I would need "1264,1284" and "98435,127.2".

    Let's assume Text wrap is off and we are only dealing with numbers.

    My Ideas.
    1) I haven't actually seen the whole file yet so lets assume there is no obvious start and end point
    Code:
    [start]1,1[stop]
    I wish...
    2) I don't think I can access the file while it's being written, unfortunately that would have made it a lot easier.

    3)Maybe I could have Scar start from the top then find how long the characters the line had then use delete until the sixth line, then down arrow 2 times then start again, But I don't know how I would find how many characters in the line using just the position of the bar thingy(the thing that blinks in front of the text you're writing ) or even locate it in the first place

    4)Count commas, I could probably do that myself with scar, maybe even with a bitmap.

    5) It also has to be very objective to work from anywhere, with no user input.

    If you have any questions please ask.

    I thank you in advance for All Ideas/Help/Noob posts to increase post count

    EDIT: I don't want to double post so here's some more info, i just got
    It will look more like this
    IGNORE LINE NUMBERS THEY CORRESPOND TO EXCEL ROWS
    remember, the comma's become
    Code:
    1: TIME, TC[i], ( If you can't figure out a way to the delete the whole line, regard I as a variable from 1-100)
    2 to about 10: (Contains useless info must be deleted)
    11+: 7:30:11, 2.4, 2.2 (Each new row has a Time stamp, the amount of columns after corresponds to the amount to TC's)
    NEW IDEA: I might be able to read the Time Stamp which will help a lot.
    For example, if the first stamp is 7:31:13, then I would delete until 7:32:13.
    Last edited by scyk123; 06-28-2009 at 02:40 PM. Reason: Update with new Info

  2. #2
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Wait, can you show me the whole thing in [C0DE][/C0DE] tags? (change the 0 to an O) and tell me which ones you need? (Don't understand what you mean by needing 1264,1284 and 98435, 127.2). Thanks ;D

  3. #3
    Join Date
    Jun 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by 99_ View Post
    Wait, can you show me the whole thing in [C0DE][/C0DE] tags? (change the 0 to an O) and tell me which ones you need? (Don't understand what you mean by needing 1264,1284 and 98435, 127.2). Thanks ;D

    I need to collect every sixth line, it records a line every 10 seconds, but I need the minute marks.

  4. #4
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    OH! Sorry, a little slow. Is there any pattern to the lines?

  5. #5
    Join Date
    Jun 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    well,
    1)Each line has the same amount of commas(except for the useless stuff part i put in my edit)

    2)Each new line is 10 seconds apart with a timestamp
    Code:
    Row1: 7:30:13, 84.3, 29.2
    Row2: 7:30:23, 84.2, 29.1
    Last edited by scyk123; 06-28-2009 at 02:52 PM. Reason: mistake

  6. #6
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Read in the whole file, then use Explode to separate it by the newline character (try using Chr(13) + Chr(10)). Once you've done that, you can loop through the array, using only every 6th value.

  7. #7
    Join Date
    Jun 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Once you've done that, you can loop through the array, using only every 6th value.
    what do you mean by that?
    Why would exploding the lines matter?


    EDIT: Are you saying I should use scar to write a new file using the sixth lines? If so thats a good idea.
    Last edited by scyk123; 06-28-2009 at 03:12 PM. Reason: Needed to be edited

  8. #8
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    The Explode command takes a single string and turns it into an array of strings, based on a set delimiter. Here's an example:
    SCAR Code:
    program New;
    var
    fileNum, i: Integer;
    fileString : String;
    explodedString : TStringArray;
    begin
      fileNum := OpenFile('Path to your file', True);
      ReadFileString(fileNum, fileString, FileSize(fileNum));
      CloseFile(fileNum);
      explodedString := Explode(Chr(13) + Chr(10), fileString);
      for i := 5 to high(explodedString) do
      begin
        Writeln(explodedString[i]);
        IncEx(i, 5);
      end;
    end.
    This will take whatever file you put into it, split it up into each separate line (assuming that the file uses the standard carriage return + line feed for each new line), then write out ever 6th value.

  9. #9
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by senrath View Post
    The Explode command takes a single string and turns it into an array of strings, based on a set delimiter. Here's an example:
    SCAR Code:
    program New;
    var
    fileNum, i: Integer;
    fileString : String;
    explodedString : TStringArray;
    begin
      fileNum := OpenFile('Path to your file', True);
      ReadFileString(fileNum, fileString, FileSize(fileNum));
      CloseFile(fileNum);
      explodedString := Explode(Chr(13) + Chr(10), fileString);
      for i := 5 to high(explodedString) do
      begin
        Writeln(explodedString[i]);
        IncEx(i, 5);
      end;
    end.
    This will take whatever file you put into it, split it up into each separate line (assuming that the file uses the standard carriage return + line feed for each new line), then write out ever 6th value.

    Supposing your doing the same thing. SRL also has a function called SRL_Explode

  10. #10
    Join Date
    Jun 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    holy s**t



    Wish i had seen that in the manual, lol, skipped right over to "File Functions".
    Finished it up with what I needed here.

    SCAR Code:
    program New;
    var
    fileNum, i, TC: Integer;
    fileString, q : String;
    explodedString : TStringArray;

    Procedure PickLines;
    begin
      q:=Readln('Location of File?'); //Can't have them touching your awesome code
      fileNum := OpenFile(q, True);
      ReadFileString(fileNum, fileString, FileSize(fileNum));
      CloseFile(fileNum);
      explodedString := Explode(Chr(13) + Chr(10), fileString);
      writeln(explodedstring[0]); //Needed to grab the firststring(title)
      for i := 1 to high(explodedString) do
      begin
        Writeln(explodedString[i]);
        IncEx(i, 5);
      end;
    end;

    Procedure Replace; //I needed to copy it back in so the data can be converted
    begin
    fileNum := RewriteFile(q, true);
    WriteFileString(fileNum, GetDebugText);
    Closefile(fileNum);
    end;

    Procedure Main; //Yes I feel it is necessary to put this little in a procedure before the final begin/end, personal preference
    begin
    cleardebug;
    PickLines;
    Replace;
    end;

    begin
    Main; //Now that's what i'm talkin' about. =)
    end.

    Thank You to everyone for helping

    99_ : Making me clear things up, it didn't really work but at least people were eventually able to figure my question out

    senrath: Introducing me to Explode(); IncEx(); then putting it all together for me. Lol, im such a noob.

    NaumanAkhlaQ: I have no idea where that is, so I have to use an unrelated smily
    Last edited by scyk123; 06-28-2009 at 05:03 PM. Reason: because i needed to! GOSH!

  11. #11
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    No problem. Glad I could help.

  12. #12
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by scyk123 View Post
    holy s**t



    Wish i had seen that in the manual, lol, skipped right over to "File Functions".
    Finished it up with what I needed here.

    SCAR Code:
    program New;
    var
    fileNum, i, TC: Integer;
    fileString, q : String;
    explodedString : TStringArray;

    Procedure PickLines;
    begin
      q:=Readln('Location of File?'); //Can't have them touching your awesome code
      fileNum := OpenFile(q, True);
      ReadFileString(fileNum, fileString, FileSize(fileNum));
      CloseFile(fileNum);
      explodedString := Explode(Chr(13) + Chr(10), fileString);
      writeln(explodedstring[0]); //Needed to grab the firststring(title)
      for i := 1 to high(explodedString) do
      begin
        Writeln(explodedString[i]);
        IncEx(i, 5);
      end;
    end;

    Procedure Replace; //I needed to copy it back in so the data can be converted
    begin
    fileNum := RewriteFile(q, true);
    WriteFileString(fileNum, GetDebugText);
    Closefile(fileNum);
    end;

    Procedure Main; //Yes I feel it is necessary to put this little in a procedure before the final begin/end, personal preference
    begin
    cleardebug;
    PickLines;
    Replace;
    end;

    begin
    Main; //Now that's what i'm talkin' about. =)
    end.

    Thank You to everyone for helping

    99_ : Making me clear things up, it didn't really work but at least people were eventually able to figure my question out

    senrath: Introducing me to Explode(); IncEx(); then putting it all together for me. Lol, im such a noob.

    NaumanAkhlaQ: I have no idea where that is, so I have to use an unrelated smily
    Doesn't matter, using it would just slow your script down on start-up

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •