0

Trying to replace MAC Addresses in a flat file. In the code below, the addresses are successfully mapping to the array. I've tried to use a counter to increment the array index on each loop, with the intent of replacing the address on line n with the nth address in the array.

The sed block effectively replaces the addresses, but only with the entry at array index 0.

mapfile -t Arr1 < <(text processing commands)

i=0  
while read line 
do
  sed -E "s/([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}/${Arr1[$i]}/"
  ((i++))
done < $macFile
1
  • Example input/output/expected output? Commented Nov 16, 2016 at 20:43

1 Answer 1

1

The problem is that sed is reading from standard input, so instead of reading the contents of the $line variable, it's reading the contents of the file designated by $macFile (except the first line, which has already been grabbed by read).

To fix this, add <<< "$line" to the end of your sed command.

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.