1

how do i assign the output of command to another variable in shell, here what i tried.

summary = `grep -A 4 '#HM based Segregation FEP (WNS)(TNS)' some_file | awk '{print $2, $3}' | sed 's/,=,//g' | tr '\n' ',' | sed 's/based Segregation,//g' | sed 's/(\|\ (/\//g' | sed 's/)//g'`
summary1 = $(grep -A 4 '#HM based Segregation FEP (WNS)(TNS)' some_file | awk '{print $2, $3}' | sed 's/,=,//g' | tr '\n' ',' | sed 's/based Segregation,//g' | sed 's/(\|\ (/\//g' | sed 's/)//g')
echo "$summary"
echo "$summary1"

basically, I am grepping from some patterns and removing unwanted data. and the output is

summary: Command not found.
Illegal variable name.

what am I doing wrong?

1

1 Answer 1

2

Shell variable assignment syntax is var=value. Remove the spaces around the equal. For example:

summary="$(grep -A 4 '#HM based Segregation FEP (WNS)(TNS)' some_file | awk '{print $2, $3}' | sed 's/,=,//g' | tr '\n' ',' | sed 's/based Segregation,//g' | sed 's/(\|\ (/\//g' | sed 's/)//g')"
Sign up to request clarification or add additional context in comments.

1 Comment

Duplicates should be closed, not answered. See the "Answer Well-Asked Questions" section of How to Answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.