How does an empty string in a file return a line break?

Source: Internet
Author: User
For example, there are such strings in the file:

A.txt

Rei9aiwe bohth4Zu Go3eimum iChieSh5iveeSh2J eiziV0bo lu2Efooz feey5Ohr

To convert into the following situation:

B.txt

Rei9aiwebohth4ZuGo3eimumiChieSh5iveeSh2JeiziV0bolu2Efoozfeey5Ohr

How to do?

Language is not limited, Php/ruby/python can.

Reply content:

For example, there are such strings in the file:

A.txt

Rei9aiwe bohth4Zu Go3eimum iChieSh5iveeSh2J eiziV0bo lu2Efooz feey5Ohr

To convert into the following situation:

B.txt

Rei9aiwebohth4ZuGo3eimumiChieSh5iveeSh2JeiziV0bolu2Efoozfeey5Ohr

How to do?

Language is not limited, Php/ruby/python can.

sed 's/\s\+/\n/g' a.txt > b.txt

Or

tr ' ' '\n' < a.txt > b.txt

or in Python:

python -c 'open("b.txt", "w").write(open("a.txt").read().replace(" ", "\n"))'

Such a task, more than a line of code is really too wasteful.

Since the language is not limited, to an alternative, visual inspection not a few know what language

Import["a.txt"]~StringReplace~(" " -> "\n") // Export["b.txt", #] &

Add a ruby version

open("b.txt", "w").puts open('a.txt').read.gsub " ", "\n"

Python

myfile = open("a.txt")temp = ""for line in myfile.readlines():    for a in line.split():         temp +=  a + '\n'myfile.close()file_object = open('b.txt', 'w')file_object.writelines(temp)file_object.close()
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.