Home > front end >  Sed replace all digits within square brackets with a new line
Sed replace all digits within square brackets with a new line

Time:07-16

My question is a both a refinement and a continuation of enter image description here

However, when I run:

sed -i 's/\[[0-9] ]/\n/g' "sentences.tmp"

--or --

sed -i 's/\[[0-9] \]\=/\n/g' "sentences.tmp"

There is no change within "sentences.tmp" upon file re-loead.

I experimented with various other forms (including replacing with 'xxx' in lieu of '\n' or '\n' or '\\n' with the same result.

My apologies for failing to provide a sample output. I have amended the question to include the guidnace thus far. Thank you.

CodePudding user response:

Using sed

$ sed -i.bak 's/\[[^]]*]=/\n/g' input_file
declare -a aRecs=(
""
"some text"
"some more text"
"three-digit text")
  • Related