A string variable taking any kind of string has a value "yjava_jboss.log4j_file_appender_pattern_layout='%d .//- %x %-5p [%c] %m%n' " at some point of time during execution. It is to greped on a file that contains with value. I used
grep "$STR" <filename> ,where STR during execution takes value as shown above. But it dint work.. I noticed that the problem is with th [ and ] meta characters
How do we escape characters when we dont even know what character is it and where is it present.???
I need the solution in shell programming.

Hello srujanasadula,

sorry for not providing a whole solution
but here are some ideas:

assuming the data to grep is in a file called "data"
you might want to try this one

#!/bin/bash
#
#

STR="yjava_jboss.log4j_file_appender_pattern_layout='%d .//- %x %-5p [%c] %m%n' "

echo "-->${STR}<--"

STR="`echo ${STR} |\
sed 's/\^/\\\^/
s/\[/\\\[/g
s/\]/\\\]/g'`"

echo "-->${STR}<--"
grep "${STR}" data

Probably you can see how the string2grep4 is changed...

Well, this is a really challenging one.
Not only that you have to recon the "meta"chars of your
implementation of [ef]grep but keep an eye on your (favorite?)
shell's interpretation of chars in her meta sense.

Pls let me know of your further proceedings (within this channel)

Kind regards,
issue9

Hello srujanasadula,

sorry for not providing a whole solution
but here are some ideas:

assuming the data to grep is in a file called "data"
you might want to try this one

#!/bin/bash
#
#

STR="yjava_jboss.log4j_file_appender_pattern_layout='%d .//- %x %-5p [%c] %m%n' "

echo "-->${STR}<--"

STR="`echo ${STR} |\
sed 's/\^/\\\^/
s/\[/\\\[/g
s/\]/\\\]/g'`"

echo "-->${STR}<--"
grep "${STR}" data

Probably you can see how the string2grep4 is changed...

Well, this is a really challenging one.
Not only that you have to recon the "meta"chars of your
implementation of [ef]grep but keep an eye on your (favorite?)
shell's interpretation of chars in her meta sense.

Pls let me know of your further proceedings (within this channel)

Kind regards,
issue9

Hello
Yeah it worked i tried.
thank You.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.