replace chars,

:rolleyes: Hi,

I want to replace the particular text in the middle of the line.
Ex. In the line 40-50 wanted to replace the char as 'x'

If x="21312312dennis3123123123"
echo ${x/dennis/xxxxxx}
x will be 21312312xxxxxx3123123123 now

echo $x |sed 's/dennis/xxxxxx/' will also give the same result.

I hope this is what you are expecting!!

something like this,
to replace in between lines with a specific character,

>cat file
this is important
>awk ' sub( substr($0, 6, 2), "x", $0) ' file
thx is important

Thanks.

Actually my doubt is :

Ex: abcdefesfe98765ksksksksk
i87838383akmsm3939398*

Now i want to replace the chars 10 - 15 position as X in this 2 lines.

Output shd be:
abcdefesfeXXXXXksksksksk
878383833XXXXX3939398*

modification to prev command,

awk ' sub( substr($0, 11, 5), "xxxxx", $0 )' file

Thank you MM :slight_smile:

Try this if you have a very big file (say 100k records)

cut -c1-9 file > tempfile1
cut -c10-15 file | tr -cd "\n" "X" > tempfile2
cut -c15- file > tempfile3

paste -d"" tempfile1 tempfile2 tempfile3

sed "s/\(.\{10\}\)\(.\{5\}\)/\1XXXXX/" file