Results 1 to 4 of 4

Thread: Make all text file content in one line if a space found

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Apr 2022
    Posts
    10
    Rep Power
    0

    Make all text file content in one line if a space found

    Make all text file content in one line if space found after a word, number, or special character


    1. I have a text file with thousands of short lines. If space is found say a (tab)
    is a space (tab)
    here.

    #Now I want to make it all in a single line together if a space (tab)
    is found after the last word in every line.


    The output will look like the below:

    1. I have a text file with thousands of short lines. If space is found say a is a space here.

    #Now I want to make it all in a single line together if a space is found after the last word in every line.


    Ps. I also want to delete all extra spaces after this.

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=SIDLFRkUEIo&lc=UgzTF5vvB67Zbfs9qvx4AaABAg
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxLtKj969oiIu7zNb94AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgzMCQUIQgrbec400jl4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg
    https://www.youtube.com/watch?v=ITI1HaFeq_g&lc=Ugx12mI-a39T41NaZ8F4AaABAg.9iDQqIP56NV9iFD0AkeeJG
    https://www.youtube.com/watch?v=vXyMScSbhk4&lc=Ugxa2VYHMWJWXA6QI294AaABAg. 9irLgSdeU3r9itU7zdnWHw
    https://www.youtube.com/watch?v=tPRv-ATUBe4&lc=UgzFkoI0n_BxwnwVMcZ4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9htG01cKBzX
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg. 9ht16tzryC49htJ6TpIOXR
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwMKwGZpDjv7vi7pCx4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg. 9ht16tzryC49htOKs4jh3M
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgxVW-am20rQ5GFuJ9F4AaABAg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 10-26-2023 at 12:21 PM.

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Hello susan santa 12345

    This is potentially quite easy if you know a couple of things about your text file
    _ 1 the format on the character(s) used as the line separator
    _ 2 how consistent that character(s) used as the line separator is.

    To explain what I am talking about:
    In computing generally, and certainly in text files, a computer knows when to make a new line in text when it sees 1 or 2 specific characters in the text string. These characters are known as
    _ the carriage return , ( in VBA coding this is the constant vbCr )
    and
    _ the line feed, ( in VBA coding this is the constant vbLf )

    Most commonly, both those 2 characters are used. But sometimes, just one of those characters is used.
    We need to know which character(s) are used in your text file, and we need to know if that is constantly the case.

    When we know this, we can replace all combination of the tab character and the new line character(s) with nothing. That effectively removes the space and the new line, which is what you want.

    One way to do this in VBA coding would be as follows:
    We would use VBA to import the text file into a single string variable,
    then do that replacing , ( so something like replacing vbTab & vbCr & vbLf with nothing,
    then remake the text file from the modified string.


    To demonstrate this VBA way, we would need a sample text file. For the demonstration we only need a text file of a few lines. ( The first thing I would do with that text file is to determine what character(s) are used for the new line, for example using my function here: https://excelfox.com/forum/showthrea...ts-of-a-string )

    ( I expect that another way to do this would be using Power Query. I don’t know how to do that, but someone else may be able to demonstrate that after I have determined what character(s) are used for the new line )


    So, in order to help you further we need a reduced size sample text file from you



    Alan

  3. #3
    Junior Member
    Join Date
    Apr 2022
    Posts
    10
    Rep Power
    0
    Please find the attached sample file.
    Attached Files Attached Files

  4. #4
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,439
    Rep Power
    10
    Hi

    These are your sample files: https://i.postimg.cc/4xHH4FN2/Before...text-Lines.jpg
    Before and After Reduce text Lines.jpg

    I won’t use those for this demonstration. I prefer to use these reduced size files
    content in one line input reduced sample.txt https://app.box.com/s/grrxh1rl372pzp2exn6em00ovhj4qhih
    content in one line output reduced sample.txt https://app.box.com/s/mpyvgf4kj9q04szjtj0255cns24lbxos

    https://i.postimg.cc/yYdStNqH/Before...ced-sample.jpg

    Before and After Reduce text Lines reduced sample.jpg


    It may be advisable for you to repeat the things that I am doing for you for more parts of the full size text file




    So I have taken a look at your files, and done a macro for you ( Sub ReplaceInTextFileThreeCharacters__Space_vbCr_vbLf_ _WithA__Space__() )
    See here for full details: https://excelfox.com/forum/showthrea...ll=1#post16696

    Here the summary:
    _ It does not appear that you have any tab characters in your text file
    _ It seems that your text file uses the typical line separator of the two character pair, a carriage return and a line feed, ( In VBA coding, vbCr & vbLf )
    _ It seems that a single space precedes the new line characters that you wish to remove

    So..
    _ The macro that I have done for you, ( Sub ReplaceInTextFileThreeCharacters__Space_vbCr_vbLf_ _WithA__Space__() ) , replaces the three character combination of a space and a carriage return and a line feed, with a single space.
    ( In the given VBA coding I replace the three character combination of " " & vbCr & vbLf with a single space " " )
    It appears to give you the results you want


    Alan






    P.S.
    Please note , susan santa 12345 et al
    _ You have a number of accounts here and at other forums. Some of your posts have been deleted and/ or your accounts banned.
    _ I expect your posts have been deleted and/ or your account banned, because of two main reasons:
    _1) You often post poorly explained questions
    _2) Often when you get help you do not give any feedback, or you do not reply. This is very uncourteous and disrespectful to the people who voluntarily give their time to help you.
    And we don't know whether or not we are wasting our time helping you because we have no reply or feedback from you.

    _ This is not the first time that I have said all this, or similar, to you.

    I appreciate that you may not understand too well the English language, and I am much more reluctant to ban people than most forum Moderators are. But if you do not improve your posting style , I will delete you and your accounts in the future.

    It is your right on a free forum to post as you choose. But if you want to continue posting in the style that you have so far, then it is probably best for you to post at the larger forums such as mrexcel.com and excelforum.com. At excelfox.com we only have a small select number of answering members, and we do not like wasting our time on people who just want a quick service to get their work done for them.
    At excelfox we are interested in helping with problems, promoting, discussing, and learning office applications, not just giving a free coding writing service.

    Seriously no hard feelings intended, , I am just telling you it as it is.

    Alan
    Last edited by DocAElstein; 09-17-2022 at 03:35 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Similar Threads

  1. VBA Range.Insert Method: Code line makes a space to put new range in
    By DocAElstein in forum Familiar with Commands and Formulas
    Replies: 9
    Last Post: 01-24-2018, 08:54 PM
  2. Replies: 2
    Last Post: 11-27-2014, 07:52 AM
  3. Replies: 6
    Last Post: 06-01-2013, 03:24 PM
  4. Make Text to Numbers Code More User Friendly
    By mrmmickle1 in forum Excel Help
    Replies: 10
    Last Post: 11-20-2012, 06:19 PM
  5. Excel found unreadable content
    By zyousafi in forum Excel Help
    Replies: 2
    Last Post: 08-08-2012, 10:41 AM

Tags for this Thread

Posting Permissions

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