i trying use sed replace string has randomly generated alphanumeric. prefixed fixed word special characters in it.
{abcd}randomalphanumric
i can replace {abcd}, don't know how replace random alphanumeric without removing other words or data on same line. able accomplish need following sed command, doesn't seem safe command use in cases. there cleaner way this?
sed -e 's/{abcd}.........../new_myvar/g'
this delete strings start {abcd}
followed number of alphanumeric character:
sed -e 's/{abcd}[[:alnum:]]*/new_myvar/g'
[[:alnum:]]
matches alphanumeric character , [[:alnum:]]*
matches 0 or more of such characters. because sed
greedy, match many alphanumeric characters possible.
example
consider test file:
$ cat file {abcd}randomalphanumric begin {abcd}adfcvr1243c end
then, our output is:
$ sed -e 's/{abcd}[[:alnum:]]*/new_myvar/g' file new_myvar begin new_myvar end
Comments
Post a Comment