pattern containg ' search and replace

Hi guys
I'm new to this forum so please help me in this
I have a file where i need to replace a pattern value=' ' with the pattern value='abc'
and moreover that abc value must be passed from some variable
say i assign name=abc and use name as the value to replace instead of the direct string abc
i tried using sed and awk
but in those i couldn check for the pattern ' because it considers it as the end of the sed command

use sed command.

sed s/' '/abc/ <filename>

using variable

sed s/' '/$variable/ <filename>

but i have so many ' ' in my file
i want to replace the pattern only having the pattern value=' '
sed is not able to do it

confused :eek:

do you want something like thi.

sed s/"=''"/abc/ filename

abc
=

it has replaced ='' with abc string.

Hi Sundarj,

Does you mean something like this:

$ cat infile
On this line varA='' is in the middle...
varB=''
This line contains '' but no variables

This command:

val=123; sed "s/varA=''/varA='$val'/g" infile

Results in:

On this line varA='123' is in the middle...
varB=''
This line contains '' but no variables

Hi,

I have a similar problem:

sed: Function s/     'yyyy-mm-dd hh24:mi:ss'/     'yyyy-mm-dd'/g  cannot be parsed.

There are numerous occurences of these timestamp masks in the 100+ files that I am editing, I only want to remove the hours, minutes and seconds from the occurences where there are five spaces before the mask. I get the error above - I don't have UNIX access from my computer right now - can anyone provide an example of how I could get this substitution to work?

(In the end I used TextPad instead :o )

 
a="My line is  2010-02-23 20:45:12 like informationsss"

maybe you can only erase "hh:mm:ss"

# echo "$a" | sed 's/20:45:12//g'
My line is  2010-02-23  like informationsss

Thank you for your reply but that would not solve my problem in this instance.

My scenario is that these should not be updated:

 between to_date(a_start_date,'yyyy-mm-dd hh24:mi:ss')
and to_date(an_end_date,'yyyy-mm-dd hh24:mi:ss')

Other sections of the file have the following as standalone lines (with five leading spaces):

     'yyyy-mm-dd hh24:mi:ss'

As I mentioned, I got round the problem using TextPad (which is a fantastic tool) so my question is an academic one about how single quotes should be managed in sed - the theme of this thread. I am hoping that someone could give me a specific solution to help my understanding.

Hi GM_AIX, Use double quotes:

sed "s/^     'yyyy-mm-dd hh24:mi:ss'/     'yyyy-mm-dd'/" infile

or

sed "s/^\(     'yyyy-mm-dd\) hh24:mi:ss'/\1'/" infile

or

sed "/^     'yyyy-mm-dd hh24:mi:ss'/s/ hh24:mi:ss//" infile

like this ?

# cat infile
     'yyyy-mm-dd hh24:mi:ss'
between to_date(a_start_date,'yyyy-mm-dd hh24:mi:ss')
and to_date(an_end_date,'yyyy-mm-dd hh24:mi:ss')
 
# sed "s/     \('yyyy-mm-dd\) hh24:mi:ss'/\1'/" infile
'yyyy-mm-dd'
between to_date(a_start_date,'yyyy-mm-dd hh24:mi:ss')
and to_date(an_end_date,'yyyy-mm-dd hh24:mi:ss')

or

# sed "s/    \('yyyy-mm-dd\) hh24:mi:ss'/     \1'/" al
      'yyyy-mm-dd'
between to_date(a_start_date,'yyyy-mm-dd hh24:mi:ss')
and to_date(an_end_date,'yyyy-mm-dd hh24:mi:ss')

ygemici, Scrutinizer,

Thank you both for your replies. I'll need to wait until tomorrow to try them out but the options certainly look plausible and you have taught me about Remembered Patterns (\1 in this case).
For anyone stumbing across this thread - I would now recommend reading: Sed - An Introduction and Tutorial.