Is something like this:
cat \"Some text here.\" > myfile.txt
Possible? Such that the contents of myfile.txt
would now be overwr
cat
can also be used following a |
to write to a file, i.e. pipe feeds cat a stream of data
Here's another way -
cat > outfile.txt
>Enter text
>to save press ctrl-d
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
simply pipeline echo with cat
For example
echo write something to file.txt | cat > file.txt
Sounds like you're looking for a Here document
cat > outfile.txt <<EOF
>some text
>to save
>EOF
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