WEIGEL FORUM
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login

    Write Text into a file and override any existing content

    Linux
    1
    1
    11
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DerMeldosD
      DerMeldos
      last edited by

      To write the text into a file and overwrite any existing content in the file, use the "cat" command with a "EOF" marker. This approach ensures all lines are written exactly as you have provided. Here’s the command:

      cat << 'EOF' > /path/to/your/file
      This is my testfile!
      #looks like a test
      EOF
      

      Replace "/path/to/your/file" with the actual path of the file where you want to write this content.

      Explanation:

      • "cat << 'EOF' > /path/to/your/file"opens a Here Document to input the text.
      • Text within the "EOF" block is written verbatim to the specified file.
      • Any "$" symbols are escaped with "" to prevent variable expansion.
      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Powered by NodeBB | Contributors