0

I'm trying to get a value from awk: I try $(), it shows bad substitution:

a=${awk 'BEGIN { last=substr("[Import][2017-10-30 02:30:45 UTC] End",10,23); print last}'}  
bash: ${awk 'BEGIN { last=substr("[Import][2017-10-30 02:30:45 UTC] End",10,23); print last}'}: bad substitution

but if I use ``, it works well:

a=`awk 'BEGIN { last=substr("[Import][2017-10-30 02:30:45 UTC] End",10,23); print last}'`

The code in awk works well. I'm trying to use awk to match the last "[Import][2017-10-30 02:30:45 UTC] End" like strings from a file. And the code is used to try.

Share a link to this question
CC BY-SA 3.0
2

1 Answer 1

0

Its not valid so, you have to create variable using myvar=$( .... ), whereas basic form of parameter expansion is ${parameter}

From

a=${awk 'BEGIN { last=substr("[Import][2017-10-30 02:30:45 UTC] End",10,23); print last}'} 

To

a=$(awk 'BEGIN { last=substr("[Import][2017-10-30 02:30:45 UTC] End",10,23); print last}') 
Share a link to this answer
CC BY-SA 3.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.