Using Cat and EOF to replace and append files in Linux

Source: Internet
Author: User

This address http://comexchan.cnblogs.com/, author Comex Chan, respecting intellectual property rights, reproduced please specify the source, thank you! 

=======================================================

Overwrite a file content directly or create a new file

=======================================================

First of all, we're looking at a test file that doesn't exist at first.

ll/tmp/

Then perform the test

cat << EOF >/tmp/test_cat_and_eof_by_comexchan-cnblogs-com_1 test cat with EOF for file overwrite or new EOF

We are looking at the contents of the file:

Cat /tmp/test_cat_and_eof_by_comexchan-cnblogs-com_1

Execute again to see if it will overwrite

cat << EOF >/tmp/test_cat_and_eof_by_comexchan-cnblogs-com_1 test cat with EOF implementation file overwrite or new [this is the second Test] EOF

Then look at the contents of the file:

Overwrite success!

=================================================

Cat combines EOF for file append

=================================================

First add some content to test

cat << EOF >/tmp/test_cat_and_eof_by_comexchan-cnblogs-com_2 test cat with EOF implementation file append [ First add some content to test]http://comexchan.cnblogs.com/EOF

And then perform the Append

cat << EOF >>/tmp/test_cat_and_eof_by_comexchan-cnblogs-com_2 test cat with EOF implementation file append [ This is the 2nd time. Append partial text]http://comexchan.cnblogs.com/EOF

Using Cat and EOF to replace and append files in Linux

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.