I'm using bash shell. I'm trying to write a script that will read a properties file and then do some replacements in another file based on the key-value pairs it reads in the file. So I have
#!/bin/bash
file = "/tmp/countries.properties"
while IFS='=' read -r key value
do
echo "${key} ${value}"
sed -ie 's/:iso=>"${key}"/:iso=>"${key}",:alpha_iso=>"${value}"/g' /tmp/country.rb
done < "$file"
but when I go to run the file, I get a "Nno such file or directory error," despite the fact my file exists (I did an "ls" after to verify it).
localhost:myproject davea$ sh /tmp/script.sh
=: cannot open `=' (No such file or directory)
/tmp/countries.properties: ASCII text
/tmp/script.sh: line 9: : No such file or directory
localhost:myproject davea$
localhost:myproject davea$ ls /tmp/countries.properties
/tmp/countries.properties
What else do I need to do to read in my properties file successfully?
while..read
to process text files you're doing it wrong (not only that but for each key=value you'll process the entire file withsed
- so one thousand lines - one thousandsed
invocations...) See the answers here: String replacement using a dictionary for proper ways to do it... – don_crissti Mar 09 '17 at 21:50file = "/tmp/countries.properties"
should be rewritten asfile="/tmp/countries.properties"
with no spaces around the=
– MikeD Mar 09 '17 at 22:24