0

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!

WorstCase
  • 25
  • 1
  • 1
  • 4

3 Answers3

0

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
Bradley Bossard
  • 2,439
  • 2
  • 23
  • 30
  • I think i neet to add some more information. I got a config-file to save username and password. Now i use a .sh to read the Logindata. I use an encryption command to encrypt my passwd variable. Now i want to export the declared variables as strings to the existing config-file. In case of existing content i would like to replace the old content with the new one. I hope you understand my broken english. – WorstCase Sep 16 '13 at 17:06
0

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.

Florian Feldhaus
  • 5,567
  • 2
  • 38
  • 46
0

try this approach :

 while read user pass;do 
    echo "$user,$pass"
    # do encrypt or other operation before echo 
  done <configfile >configfile.new
michael501
  • 1,452
  • 9
  • 18