1

I am comparing two files and displaying the lines which are not similar, when I just keep

echo $(awk 'FNR==NR{f[$0]+=1; next} !($0 in f)' $file1 $file2)

I am able to get the values.

When I try to do the same by passing into array , I am getting ":command not found" error

declare -a myarr=()
myarr=$("$(awk 'FNR==NR{f[$0]+=1; next} !($0 in f)' $file1 $file2 )")

Please help , thanks in advance.

1
  • Why are you doing +=1? Nothing in your code uses it afterwards. Commented Oct 24, 2018 at 15:29

1 Answer 1

2

Remove the quotes plus the leading dollar:

myarr=$("$(awk 'FNR==NR{f[$0]+=1; next} !($0 in f)' $file1 $file2 )")

should be

myarr=($(awk 'FNR==NR{f[$0]+=1; next} !($0 in f)' $file1 $file2))

Check:


Btw, your awk command won't print lines which are unique to file1. Probably the comm command is what you want, but note that comm expects sorted input:

comm -13 <(sort "${file1}") <(sort "${file2}")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.