Question

I would like to export an encrypted string to a file that already has some content.

How can i delete the content of this file and add my string?

I tried cat but that did not work. Thanks for your help!

Was it helpful?

Solution

In Bash you can easily redirect a string into a file with bash like this

echo "This is my string" > filename

A single > will replace the contents, >> will append the string to the end of the file.

For more information have a look at the bash manual regarding Redirection.

OTHER TIPS

Use the > redirection operator, it will wipe out the target file. Use the >> to append to the end of the target file

cat encrypted_file.txt > desired_file.txt

try this approach :

 while read user pass;do 
    echo "$user,$pass"
    # do encrypt or other operation before echo 
  done <configfile >configfile.new
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top