Extract a string out of key, value from a text file, and assign to a new variable
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Need a script to iterate through below file to read keys, values and extract values eg. foo_key1, foo.com, /tmp/worker$Build_Number out of key and values assign them to another variable (eg. A="foo_key1", B="foo.com", C="/tmp/worker$Build_Number").
cat abc.txt
foo_key1=foo.com|/tmp/worker$Build_Number
foo_key2=goo.com|/tmp/manager$Build_Number
I have tried the below code but no luck.
while IFS== read -r key val ; do
val=$val%"; val=$val#"; key=$key#export ;
A="$(cut -d'_' -f1 <<<"$key")"
B="$(cut -d'_' -f1 <<<"$val")"
C="$(cut -d'_' -f2 <<<"$val")"
echo $A
echo $B
echo $C
done < abc.txt
Expected output:
foo_key1
foo.com
/tmp/worker$Build_Number
linux shell regular-expression python
add a comment |Â
up vote
0
down vote
favorite
Need a script to iterate through below file to read keys, values and extract values eg. foo_key1, foo.com, /tmp/worker$Build_Number out of key and values assign them to another variable (eg. A="foo_key1", B="foo.com", C="/tmp/worker$Build_Number").
cat abc.txt
foo_key1=foo.com|/tmp/worker$Build_Number
foo_key2=goo.com|/tmp/manager$Build_Number
I have tried the below code but no luck.
while IFS== read -r key val ; do
val=$val%"; val=$val#"; key=$key#export ;
A="$(cut -d'_' -f1 <<<"$key")"
B="$(cut -d'_' -f1 <<<"$val")"
C="$(cut -d'_' -f2 <<<"$val")"
echo $A
echo $B
echo $C
done < abc.txt
Expected output:
foo_key1
foo.com
/tmp/worker$Build_Number
linux shell regular-expression python
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Need a script to iterate through below file to read keys, values and extract values eg. foo_key1, foo.com, /tmp/worker$Build_Number out of key and values assign them to another variable (eg. A="foo_key1", B="foo.com", C="/tmp/worker$Build_Number").
cat abc.txt
foo_key1=foo.com|/tmp/worker$Build_Number
foo_key2=goo.com|/tmp/manager$Build_Number
I have tried the below code but no luck.
while IFS== read -r key val ; do
val=$val%"; val=$val#"; key=$key#export ;
A="$(cut -d'_' -f1 <<<"$key")"
B="$(cut -d'_' -f1 <<<"$val")"
C="$(cut -d'_' -f2 <<<"$val")"
echo $A
echo $B
echo $C
done < abc.txt
Expected output:
foo_key1
foo.com
/tmp/worker$Build_Number
linux shell regular-expression python
Need a script to iterate through below file to read keys, values and extract values eg. foo_key1, foo.com, /tmp/worker$Build_Number out of key and values assign them to another variable (eg. A="foo_key1", B="foo.com", C="/tmp/worker$Build_Number").
cat abc.txt
foo_key1=foo.com|/tmp/worker$Build_Number
foo_key2=goo.com|/tmp/manager$Build_Number
I have tried the below code but no luck.
while IFS== read -r key val ; do
val=$val%"; val=$val#"; key=$key#export ;
A="$(cut -d'_' -f1 <<<"$key")"
B="$(cut -d'_' -f1 <<<"$val")"
C="$(cut -d'_' -f2 <<<"$val")"
echo $A
echo $B
echo $C
done < abc.txt
Expected output:
foo_key1
foo.com
/tmp/worker$Build_Number
linux shell regular-expression python
linux shell regular-expression python
asked 56 secs ago
itgeek
201
201
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475927%2fextract-a-string-out-of-key-value-from-a-text-file-and-assign-to-a-new-variabl%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password