ATP
ATP

Reputation: 1

sed command is not working properly

I'm trying to replace the word in shell script with sed -e command but its not replacing , please help on that, i have tried the below

we have separate file in /data/docs/config.log, in that file there is a word ?account for example ,

username acc, passsword acc, ?account.name

this ?account word needs to be replaced with word 'GLOBAL' using sed -e command ,

reacc = GLOBAL

sed -e "s/?account/$reacc/g" /data/docs/config.log > /data/docs/newconfig.log 

but here the file newconfig.log has created with 0 size , no output written to the file , its not replacing its an empty file,

the output should be username acc, passsword acc, GLOBAL.name in newconfig.log

Upvotes: 0

Views: 412

Answers (2)

Ruud Helderman
Ruud Helderman

Reputation: 11018

Being the only person who can reproduce the problem, you are pretty much on your own. There are plenty of things you can do to analyze the problem, though.

  • Double-check the shell. Don't have blind faith in #!/bin/sh. In cygwin for example, /bin/sh is an alias for bash. Verify with: echo $SHELL
  • Check permissions and file system. Do you have rights to write to the output file? Is the disk full? Does cat /data/docs/config.log > /data/docs/newconfig.log work? Test again in a different folder.
  • Double-check the output file. Is it really empty, or is the file system just slow with updating the file size? Is sed really finished? Test without output redirection; see if the output is dumped to stdout.
  • Test with a small file; one or two lines is enough.
  • If even that does not work, then test sed itself. Who knows, maybe you have a weird alias that hides the real sed. The most trivial filter is sed -e '', which should simply echo every line you type (just like cat without parameters). Does that work? Then try some simple patterns.

Systematically iterate between test cases that succeed and test case that fail, until you have found the breaking point. Doing so, you should be able to find the cause. Sorry, that's all I can do for you right now.

Upvotes: 1

Amit
Amit

Reputation: 20496

Remove spaces around =. Try after making

reacc=GLOBAL

Upvotes: 0

Related Questions