awk에서 shell로 변수 가져오기
https://stackoverflow.com/questions/14505026/set-variable-in-current-shell-from-awk
Set variable in current shell from awk
Is there a way to set a variable in my current shell from within awk? I'd like to do some processing on a file and print out some data; since I'll read the whole file through, I'd like to save the
stackoverflow.com
Here's another way.
This is especially useful when when you've got the values of your variables in a single variable and you want split them up. For example, you have a list of values from a single row in a database that you want to create variables out of.
val="hello|beautiful|world" # assume this string comes from a database query read a b c <<< $( echo ${val} | awk -F"|" '{print $1" "$2" "$3}' ) echo $a #hello echo $b #beautiful echo $c #world
We need the 'here string' i.e <<< in this case, because the read command does not read from a pipe and instead reads from stdin