Can linux cat command be used for writing text to file?

后端 未结 12 1137
南方客
南方客 2021-01-29 19:03

Is something like this:

cat \"Some text here.\" > myfile.txt

Possible? Such that the contents of myfile.txt would now be overwr

相关标签:
12条回答
  • 2021-01-29 19:51

    cat can also be used following a | to write to a file, i.e. pipe feeds cat a stream of data

    0 讨论(0)
  • 2021-01-29 19:57

    Here's another way -

    cat > outfile.txt
    >Enter text
    >to save press ctrl-d
    
    0 讨论(0)
  • 2021-01-29 19:58

    Write multi-line text with environment variables using echo:

    echo -e "
    Home Directory: $HOME \n
    hello world 1 \n
    hello world 2 \n
    line n... \n
    " > file.txt 
    
    0 讨论(0)
  • 2021-01-29 20:01

    simply pipeline echo with cat

    For example

    echo write something to file.txt | cat > file.txt
    
    0 讨论(0)
  • 2021-01-29 20:05

    Sounds like you're looking for a Here document

    cat > outfile.txt <<EOF
    >some text
    >to save
    >EOF
    
    0 讨论(0)
  • 2021-01-29 20:05

    The Solution to your problem is :

    echo " Some Text Goes Here " > filename.txt

    But you can use cat command if you want to redirect the output of a file to some other file or if you want to append the output of a file to another file :

    cat filename > newfile -- To redirect output of filename to newfile

    cat filename >> newfile -- To append the output of filename to newfile

    0 讨论(0)
提交回复
热议问题