1

One of my file abc.txt contains below path as one of the line.

/lz/BEN_BOB.success

It is to be replaced as below

/lz/BEN_B.success

I'm generating these names during runtime hence storing in variables as below.

SUCCESS_FILE=/lz/BEN_BOB.success
NEW_SUCCESS_FILE=/lz/BEN_B.success

I'm using below command to replace but not working.

cat abc.txt | sed "s/$SUCCESS_FILE/$NEW_SUCCESS_FILE/g".

Is it because I have / symbol in variables?

As mentioned it is in korn shell.

5
  • avoid useless use of cat Commented Sep 8, 2016 at 10:02
  • Removed cat and use direct sed on filename. Same wrong output Commented Sep 8, 2016 at 11:48
  • yup, both are equivalent command, just that you didn't need to use cat Commented Sep 8, 2016 at 11:52
  • True. Please provide me the solution for given problem. Commented Sep 8, 2016 at 12:17
  • The answer of @oliv seems right. Can you echo "SUCCESS_FILE=${SUCCESS_FILE}"? Maybe the runtime generation (in a subshell?) went wrong. Commented Sep 8, 2016 at 21:16

1 Answer 1

1

You can use another delimiter in your sed command (e.g. | instead of /):

sed "s|$SUCCESS_FILE|$NEW_SUCCESS_FILE|g" abc.txt
Sign up to request clarification or add additional context in comments.

1 Comment

then please update your question with the real content of file abc.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.