Skip to main content
deleted 8 characters in body; edited tags; edited title
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265

Donot Do not replace the second occurrence of pattern in a same word in the file with sed command

echo "abcdef12cade 12345678 abcdefba12345678" | sed -E "s/[0-9a-fA-F]{8}/00000000/g" 

the above outputs the following

00000000cade 00000000 0000000000000000

it is replacing the pattern for second occurrence in a same word. I don't want to replace if there is a second occurrence.

expected ouput

00000000cade 00000000 abcdefba12345678

Donot replace the second occurrence of pattern in a same word in the file with sed command

echo "abcdef12cade 12345678 abcdefba12345678" | sed -E "s/[0-9a-fA-F]{8}/00000000/g" 

the above outputs the following

00000000cade 00000000 0000000000000000

it is replacing the pattern for second occurrence in a same word. I don't want to replace if there is second occurrence.

expected ouput

00000000cade 00000000 abcdefba12345678

Do not replace the second occurrence of pattern in a same word in the file with sed command

echo "abcdef12cade 12345678 abcdefba12345678" | sed -E "s/[0-9a-fA-F]{8}/00000000/g" 

the above outputs the following

00000000cade 00000000 0000000000000000

it is replacing the pattern for second occurrence in a same word. I don't want to replace if there is a second occurrence.

expected ouput

00000000cade 00000000 abcdefba12345678
Markup.
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
echo "abcdef12cade 12345678 abcdefba12345678" | sed -E "s/[0-9a-fA-F]{8}/00000000/g" 

echo "abcdef12cade 12345678 abcdefba12345678" | sed -E "s/[0-9a-fA-F]{8}/00000000/g" thethe above outputs the following

"00000000cade 00000000 0000000000000000"

00000000cade 00000000 0000000000000000

it is replacing the pattern for second occurrence in a same word. I don't want to replace if there is second occurrence.

expected ouput "00000000cade 00000000 abcdefba12345678"

00000000cade 00000000 abcdefba12345678

echo "abcdef12cade 12345678 abcdefba12345678" | sed -E "s/[0-9a-fA-F]{8}/00000000/g" the above outputs the following

"00000000cade 00000000 0000000000000000"

it is replacing the pattern for second occurrence in a same word. I don't want to replace if there is second occurrence.

expected ouput "00000000cade 00000000 abcdefba12345678"

echo "abcdef12cade 12345678 abcdefba12345678" | sed -E "s/[0-9a-fA-F]{8}/00000000/g" 

the above outputs the following

00000000cade 00000000 0000000000000000

it is replacing the pattern for second occurrence in a same word. I don't want to replace if there is second occurrence.

expected ouput

00000000cade 00000000 abcdefba12345678
Source Link

Donot replace the second occurrence of pattern in a same word in the file with sed command

echo "abcdef12cade 12345678 abcdefba12345678" | sed -E "s/[0-9a-fA-F]{8}/00000000/g" the above outputs the following

"00000000cade 00000000 0000000000000000"

it is replacing the pattern for second occurrence in a same word. I don't want to replace if there is second occurrence.

expected ouput "00000000cade 00000000 abcdefba12345678"