How to get rid of empty lines in a file?

How can read a file "text.txt", delete all the empty lines and restore it to same filename "text.txt" without using a temporary file?

Ages ago I ruined an 8" floppy disk drive by doing something similar to
this: let b1 b2 ... bn nl be a series of blanks followed by a newline
character (nl) and let c1 ... cm be a sequence of other characters. Let
the total relevant sequence be:
b1 b2 ... bn nl c1 ... cm
Reverse the entire sequence: cm ... c1 nl bn ... b2 b1 and then
reverse the first m bytes: c1 cm nl bn ... b2 b1. Now repeat the entire
thing for the sequence c1 ... cm by checking for more blank lines in it.
After this has all finished, simply truncate the file.
The advantage of this method was that I only needed to be able to swap
two bytes in a file; the disadvantage was that the floppy disk drive
couldn't handle it ;-)
kind regards,
Jos

Similar Messages

  • How to get rid of empty track.

    Ok, another question for you. How do I get rid of empty track? I've got my film and then loads of empty track that I cant get rid of and when I put it into Quicktime it copies all the empty stuff too and it takes twice as long.

    You explained it fine. FCP recognizes the end of your sequence. YOu can't delete the end. If you are getting loads of black at the end of your movie that would suggest that you have a clip somewhere way down the line that you are not seeing. Press shift-z to fit the timeline in the timeline window. Your movie should fill the timeline. If not, look at the end of the timeline and delete any media that you don't want to be included.

  • How to get rid of the line encasing the left hand side of a vertical spry menu?

    Hi,
    I have created a vertical spry menu bar. It all works but there is a line like this [  encasing the left hand side of the menu. Does anyone know how to get rid of this?
    Thanks!

    Line 73 in your Spry css calls for a border
    ul.MenuBarVertical{
        border: 1px solid #ccc;
    Either remove the rule or change the #ccc to #fff

  • How to get rid of hash lines on tabs,ive been told that you have to down grade to wot.. true not true

    randomly hash lines will appear on tabs and continue across every tab when open... how do i get rid of this whit out down gradeing to a previous version?

    ''cor-el [[#answer-713567|said]]''
    <blockquote>
    You can try to disable hardware acceleration in Firefox.
    *Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    You need to close and restart Firefox after toggling this setting.
    *https://support.mozilla.org/kb/upgrade-graphics-drivers-use-hardware-acceleration
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem.
    *Switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance
    *Do NOT click the Reset button on the Safe Mode start window
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    </blockquote>

  • How to get rid of "empty" volume

    I have a Standard setup of Leopard Server.
    When each user connects to the server the get an option to mount an "empty" volume. What's this and can I get rid of it without breaking anything?

    Workgroup Manager that is. Thanks, that did the trick.
    Also, all you need to do is select 'None' then save and it gets rid of the var in the process.
    Message was edited by: Christiaan

  • How to get characters from a line in a file ?

    Hello Everybody ,
    I am able to read the lines from the file using readLine( ) method.
    But i do not want to read anything that comes after the character '#'
    Any thing that follows a '#' character is considered as a commet in my case.
    The contents of my input file are,
    #Character mappings for Japanese Shift-JIS character set
    #ASCII character Mapped Shift-JIS character
    m 227,128,133 #Half width katakana letter small m
    n 227,128,134 #Half width katakana letter small n
    o 227,129,129
    p 227,129,130
    q 227,129,131
    r 227,129,132
    s 227,129,133
    t 227,129,134
    u 227,129,135
    v 227,129,136
    w 227,129,137
    x 227,129,138
    y 227,129,139
    z 227,129,142
    My code to read the contents of the file is,
    import java.io.*;
    class Read
    public static void main(String s[])
    try{
    int i=0,j,l;
    BufferedReader in=new BufferedReader(
    new InputStreamReader(
    new FileInputStream("Character.txt")));
    String []str=new String[100];
    while(true)
    str=in.readLine();
    if(str[i]==null) break;
    System.out.println(str[i]);
    i++;
    catch(Exception e)
    e.printStackTrace();
    System.out.println(e);
    How do i store the values within a line in the file
    to two different variables
    Like say,
    I read the line
    i get the character 'm' store it in a variable say, char ch='m' ;
    and the corresponding value 227,128,133 in a String variable.
    String str="227,128,133";
    Please offer some suggesstions and help me out .
    Any suggesstions would be welcome and very useful.
    Thanks and regards
    khurram

    It depends on whether the format of the file will ever change. If the "rules" regarding the structure of the file are predictable, then it's fairly simple.
    In the sample file, if we assume that anything that starts with # should be ignored, and all relevant lines begin with single char, followed by three comma separated integers; then you can just do the following (haven't tested this)
    import java.io.*;
    class Read
         public static void main(String s[])
              try{
                   // Create a Map to store the results..
                   Map data = new HashMap();
                   // We will store the actual values in an array
                   int[] values = null;
                   // Each valid line has a character
                   char theChar;
                   // Temp storage for the integer values
                   String[] strValues = null;
                   BufferedReader in=new BufferedReader(
                   new InputStreamReader(
                   new FileInputStream("Character.txt")));
                   String str=null;
                      while(true)
                        str=in.readLine();
                        if(str==null) break;
                        // trim to remove any spaces
                        str = str.trim();
                        theChar = str.charAt(0);
                        if(theChar != '#') {
                             // not a comment
                             // Split to get the int
                             strValues = str.substring(1, str.length()).split(",");
                             // We only want the first 3 tokens
                             values = new int[3];
                             for(int i = 0; i < values.length; i++) {
                                  values[i] = Integer.parseInt(strValues);
                             // Now, add the results to the map
                             data.put(String.valueOf(theChar, values);
                             System.out.println(str);
              catch(Exception e)
                   e.printStackTrace();
                   System.out.println(e);
    This will leave you with a Map of the character mappings, keyed on the String value of the character (just because you can't store a char in a Map)

  • How to get the number of lines of a file?

    Folks:
    Is there a way to get the number of lines of a text file? I don't know if there is an existing method to do that.
    Thanks a lot.

    HI
    I found some solution
    other than increment loop and all
    here is the code it might helpful to u
    //returns the number of lines in a file
    //author : Ravindra S
    //Symphony software Hyderabad
    try
    RandomAccessFile randFile = new RandomAccessFile(csvFile,"r");
    long lastRec=randFile.length();
    randFile.close();
    FileReader fileRead = new FileReader(csvFile);
    LineNumberReader lineRead = new LineNumberReader(fileRead);
    lineRead.skip(lastRec);
    countRec=lineRead.getLineNumber()-1;
    fileRead.close();
    lineRead.close();
    catch(IOException e)

  • How to get rid of empty space in module pool screen?

    Hello Experts,
    In module pool, I have 2 table controls inside 2 separate boxes in the same screen. Based on some conditions I hide the first table control. It's all working fine. But the space where first table is created remains blank in the screen. I don't want that.If the first table control is hidden the second table control should occupy the empty space. I do not want empty space in the screen.
    How can I acheive this.Is there anything I can set in the screen attribute level.
    Thanks.
    Yasin.

    Hi Yasin,
    As you said you have 2 sub screen areas and also 2 subscreens.
    when hide the First subscreen from First Subscreen area, you need to assign the second subscreen on to the first subscreen area and a dummy subscreen on to second subscreen area, this is a kind of work around and bit tricky playing with screen elements
    in Top Include
    data dynnr type sy-dynnr value '100' " your default Subscreen number
    in PBO
    call subscreen sub1 including sy-repid dynnr1 " First Sub screen area
    call subscreen sub2 including sy-repid dynnr2 " Second sub screen area
    in PAI
    module call_dyn_number.
    in program.
    case ok_code.
    when 'HIDE'. " When you hide the first table control
    dynnr1 = '200' " This is your second table control containing Screen number
    dynnr2 = '300'. "This is a Dummy Screen Number which doesnt contain any screen elements so output is plain
    " Note: This is a crude IDEA only as you try to implement you need to adjust this for the expected outcome
    " I implemented this earlier but dont have complete ref at this moment
    endcase.
    Hope this serves your purpose
    Cheerz
    Ram

  • How to get rid of a line from rectangle shape?

    usually my eraser tool works fine, but when i try to erase a line from a rectangle i made, it creates a black outline instead of erasing it. i took a video of what happens:
    the rectangle is over the image, which is made of regular lines. though i don't think that's causing the problem.

    Hi
    When you erase using the eraser tool the outline or stroke gets distorted creating a black outline. Try using the delete anchor tool or the Direct selection tool.
    You can even merge the triangle with the rectangle using the unite in path finder. (window -> path finder) shift ctrl+f9 
    Thanks
    Digiscape Gallery
    www.digiscapegallery.com

  • How to get rid of black line on iPhone??

    I SUDDENLY have a thin black line on the left side on my iphone screen......can anybody help me with this?  This is the first time I've ever seen this.  thank you.

    Likely a hardware problem.
    If no change after powering the iPhone off and on, try restoring the iPhone with iTunes as a new iPhone or not from the backup. If no change after that, it is a hardware problem.

  • I have very thin, colored lines running vertical on my desktop monitor screen.  I don't know where they come from or how to get rid of them.  I started with one and now have three.  Can anyone give me some insight about what to do in getting rid of them?

    I have very thin, colored lines that have shown up on my IMac monitor screen.  I don't know where they came from or how to get rid of them.  I'm concerned now because I started with one and now have three.  Does any know why this occurs or how to get rid of them?

    I got an address from Applecare, although I can't place my hand on it right now. I didn't bother persuing the letter route myself as I didn't expect much. I know that the location was Cork, Ireland though as that where the UK Applecare is based as far as I'm aware. The best thing to do is to call Applecare (if it's free) and discuss the issue. State that you are not happy wit the fact that you will have to pay to have the problem resolved especiiay if it is an ongoing problem that has not been resolved. I ended up speaking to a senior manager of the Applecare team who then proceeded to tell me about mailing in my grievence to customer services division or something like that.
    If I can find the address I may post it if I'm allowed.
    In the case of age, Schools usually have a 5-year life-cycle as they tend to be used differently than consumer machines, i.e. being used constantly on a daily basis for at least 12 hours with no break. you would expect issues to appear after a few years, but I expect problems that arise through defects to be resolved and stay resolved. As I mentioned we had machines for around 2 years before the lines appeared and sent them to be repaired. I'm happy with that. What I am unhappy about is the fact that the problem has reappeared exactly in the same way and now I'm left with around 7 machines that I either pay loads to repair or, the more likely replace the machines with newer ones since the age is now big enough to warrant the replacement.
    Sorry for the lengthy moan, but these are the reasons I purchased Apple ahrdware in the first place to avoid the "not our problem" stance some PC vendors  usually take, similar to the Dell monitors thread mentioned in here somewhere.

  • How to get rid of a "not assigned" line in Bex

    Hello Experts,
    I feed a Cube with two ODS-Objects, one fpr orders and one for items.
    ODS1 provides the number of orders and
    ODS2 provides the number of items and the charachteristic item_type for the dimension item.
    Because the charachteristic item_type is not provided by ODS1 there is a "not assigned" line at the bottom of the table in Bex!
    How can I get rid of this line? I want to avoid usong seperate Cubes for Orders and Items!
    thanx
    hiza

    Hi Hiza.
    In the query designer restrict item_type to # -> right click on # -> exclude from selection.
    Hope it helps.
    BR
    Stefan

  • How to get rid of the reference lines on the front panel

    I forgot how I created a couple of horizontal and vertical reference lines on the front panel. It looks like the origin lines on the front panel. When I move my program to another monitor with different resolution, all the layout is messed up because of the reference lines can not change with the resolution. Did anybody meet this before? How to get rid of them?
    Attached are the 2 creen shot of front panels.
    Thanks in advanced.
    Solved!
    Go to Solution.
    Attachments:
    front panel.png ‏63 KB
    front panel2.png ‏42 KB

    You will have to click on the top menu and choose options see below
    when you do this window will pop up and you scroll down until you get to the front panel options. See below
    Tim
    Johnson Controls
    Holland Michigan

  • I keep getting a blue line under text in e mail signatures, its not a hyperlink. Any ideas on how to get rid of it?

    I keep getting a blue line when I set up signatures in Mail. Has anyone come accross this? If so any ideas on how to get rid?

    http://www.apple.com/support/safari/ you may have just needed to clear your cookies and data.
    http://support.apple.com/kb/HT4211 closing Safari from running in the backgound sometimes helps.
    http://support.apple.com/kb/HT4946 backing up is worth the short time it takes.  It sure beats re adding your contacts by maually.

  • A line appeared in the backdrop, how to get rid of it?  (and how did it get there?)

    the site was published and everything looked great, except we had to make several changes to the content and somehow along the way a line appeared on the master page (hence appearing on all pages).  i can't figure out how to get rid of it, and it's driving me nuts.  any advice would be much appreciated.
    thank you in advance for you help!

    Hello,
    Are you talking about the Shadow effect on the page : http://trainingwebcom.worldsecuresystems.com/SachinFTP/2013-12-05_1415.png
    Or is it about the line on the homepage : http://trainingwebcom.worldsecuresystems.com/SachinFTP/2013-12-05_1416.png
    In case it is about the shadow, please go to Master page, click on some blank area and check in the toolbar at the top if there is some effect applied to page : http://trainingwebcom.worldsecuresystems.com/SachinFTP/2013-12-05_1417.png
    It can be Shadow, Bevel or Glow effect applied. You can uncheck it and it should be good.
    Let us know if it helps or not.
    Regards,
    Sachin

Maybe you are looking for