Issue
I have a file with following content:
Blekota blaboli o koblihach.
Blanka je bl...
GEwI
er
I need to replace every word starting with Bl
or bl
with xxxx
and save it into new file. I try this, but it did not work.
while read line;
do pokus="${line//[Bl|bl].* /xxxx}"
echo $pokus
done < "$TEXT" > "$TEXT".new
Desired output is:
xxxx xxxx o koblihach.
xxxx je xxxx...
GEwI
er
What do I do wrong, please?
Solution
This can be done using a sed
command:
sed 's/\<[Bb]l[[:alpha:]]*/xxxx/g' file
xxxx xxxx o koblihach.
xxxx je xxxx...
GEwI
er
Here \<[Bb]l[[:alpha:]]*
matches a word starting with Bl
or bl
followed by 0 or more alphabets.
Answered By - anubhava Answer Checked By - Clifford M. (WPSolving Volunteer)