"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
You can't use awk and read and write from the same file (is part of your problem) I prefer to rename the file before I rewrite (but you can save to a tmp and then rename too) bin/mv file file. Tmp awk '.... code ...' file. Tmp > file If your env file gets bigger, you'll see that is is getting truncated at the buffer size of your OS Also, don't forget that gawk (the std on most Linux installations) has a built in array ENVIRON.
You can create what you want from that awk 'END { for (key in ENVIRON) { print key "=" ENVIRONkey } }' /dev/null Of course you get everything in your environment, so maybe more than you want. But probably a better place to start with what you are trying to accomplish Edit Most specifically awk -F"=" '{ if ($1 in ENVIRON) { printf("%s=%s\n", $1, ENVIRON$1) } # else line not printed or add code to meet your situation }' file > file. Tmp /bin/mv file.
Tmp file Edit 2 I think your var=values might need to be export ed so they are visible to the awk ENVIRON array AND echo PATH=xxx| awk -F= '{print ENVIRON$1} prints the existing value of PATH I hope this helps P.S. As you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.
You can't use awk and read and write from the same file (is part of your problem). I prefer to rename the file before I rewrite (but you can save to a tmp and then rename too). /bin/mv file file.
Tmp awk '.... code ...' file. Tmp > file If your env file gets bigger, you'll see that is is getting truncated at the buffer size of your OS. Also, don't forget that gawk (the std on most Linux installations) has a built in array ENVIRON.
You can create what you want from that awk 'END { for (key in ENVIRON) { print key "=" ENVIRONkey } }' /dev/null Of course you get everything in your environment, so maybe more than you want. But probably a better place to start with what you are trying to accomplish. Edit Most specifically awk -F"=" '{ if ($1 in ENVIRON) { printf("%s=%s\n", $1, ENVIRON$1) } # else line not printed or add code to meet your situation }' file > file.
Tmp /bin/mv file. Tmp file Edit 2 I think your var=values might need to be export -ed so they are visible to the awk ENVIRON array. AND echo PATH=xxx| awk -F= '{print ENVIRON$1}' prints the existing value of PATH.
I hope this helps. P.S. As you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.
Thanks for having a shot, but again I don't think I've made myself clear. Is there a sh/sed/awk equivalent of: perl -ne '/^(^=+)/; print "$1=$ENV{$1}\n";'? – Simon May 4 at 3:12 Thanks again.
Your edit seems to be more like what I'm after, however the ENVIRON$1 statement doesn't expand properly. Are you able to double-check that? – Simon May 4 at 4:27.
I don't exactly know what you are trying to do, but if you are trying to change the value of variable THREE , awk -F"=" -vt="$THREE" '$1=="THREE" {$2=t}{print $0>FILENAME}' OFS="=" vars.
Sorry for not being clearer. I want to read variables from a file into the environment (the file is snippet #1). Then I want to update one or two of the variables in the environment (updating THREE is only an example, it could be any of the variables), then rewrite the file with updated values.So: read, change, write.
The trick is only writing back variables that were in the file in the first place (not the whole environment). And preserving comments in the original file would be nice. – Simon May 4 at 2:08.
You can do this in just with bash: rewrite_config() { local filename="$1" local tmp=$(mktemp) # if you want the header echo "# File: $filename" >> "$tmp" while IFS='=' read var value; do declare -p $var | cut -d ' ' -f 3- done > "$tmp" mv "$tmp" "$filename" } Use it like source network. Config # manipulate the variables rewrite_config network. Config I use a temp file to maintain the existance of the config file for as long as possible.
Thanks Glenn, this is a good solution. I hadn't thought of using declare. Note that including the header (as in your example) clobbers subsequent calls to rewrite_config, but otherwise it's good.
– Simon May 5 at 1:48 I was bouncing around with various eval solutions until I read about declare. – glenn jackman May 5 at 13:15.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.